I am trying to implement on my website a simple and friendly address system.
What i'm thinking about is when the user logged in, his username will be displayed in the address bar.
- www.example.com/username1 (for home page profile)
- www.example.com/username1/about/
- www.example.com/username1/gallery/
- www.example.com/username2 (for home page profile)
- www.example.com/username2/about/
- www.example.com/username2/gallery/
And additionally if anyone enter the address www.example.com/username1, will be shown the profile of user1.
I already implemented a register/Login system using Django-Allauth
mySite/urls.py
url(r'^accounts/', include('allauth.urls')),
home/urls.py
url(r'^$', views.index),
home/views.py
def index(request):
return render_to_response('home/index.html', context_instance=RequestContext(request))
I tried to follow some examples like Facing problem with user profile url scheme like example.com/username in django
But i dont have this thing working yet. I dont understand what to do :(
Please, give some advise.
1. Regarding
Based on the answer from https://stackoverflow.com/a/20143515/4992248
Would be better to use
get_absolute_url
, iereturn 'request.user.get_absolute_url'
. In this case you need to do:2. Regarding
catavaran
wrote correct urls which leads toviews.profile
, so inview.py
you need to write:In template (i.e.
profiles.html
) you can show user's data via{{user_profile_form.as_p}}
Add the following url as the last item of the
mySite/urls.py
:Then the
username
parameter will be passed to the views of youruserapp
:userapp/urls.py
:userapp/views.py
:It's almost perfect, but i have a bug. Let me explain. When i login (my login system is: django-allauth) on the
http://127.0.0.1:8000/accounts/login/
i return tohttp://127.0.0.1:8000
with an error 404.I am not getting the http://127.0.0.1:8000/username/ with the template, when the login botton is clicked.
The instalation of django-allauth require adding to the settings.py
How can i redirect to http://127.0.0.1:8000/username/ and show the correct template?