Answer the question
In order to leave comments, you need to log in
How to create a custom /username binding for each object in the database?
Tell me how to create for each object its own url binding, for example 127.0.0.1:800/Rassul. Tried like this but only creates one page : File urls.py in applications:
for i in account.objects.all():
if i.account_login == i.account_login:
userlogin = i.account_login
print(userlogin)
urlpatterns = [
path('', views.main, name = 'main'),
path('forgot', views.forgot, name = 'forgot'),
path('addaccount', views.addaccount, name = 'addaccount'),
path(userlogin, views.profile, name = userlogin)
]
def profile(request):
for a in account.objects.all():
return render(request, 'index.html')
Answer the question
In order to leave comments, you need to log in
No need to create a url for each user. It is enough to create a universal url using regular expressions
. In your case, there will be something like
path('bio/<username>/', views.bio, name='bio')
# или
re_path(r'^bio/(?P<username>\w+)/$', views.bio, name='bio')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question