Question

when using django-registration , the url confuse me a bit

say i want my inidex page localhost:8000 to be a login page, but the django-registration's login url has a /login prefix, do i have to put the /login in my url like

url(r'^/login/$', include('registration.backends.default.urls')),

in this case , the localhost:8000 will be empty, dose it mean after deploy this project ,view the url like something.com will be empty.

how to set the index page to be a actual django-registration login page

Was it helpful?

Solution

No not really, you need to include the @login_required decorator on the views that you want the user to be authenticated, for eg.

# views.py

from django.contrib.auth.decorators import login_required
from django.http import HttpResponse

@login_required
def index(request):
    return HttpResponse('Only registers will see this page')

# now you can add the stuff that you would want only the registered users to view, 
# so basically if a new visitors tries to visit your site say at www.abc.com, he will first be redirected to the www.abc.com/login/ where he needs to create an account, once authenticated, he will then be redirected to the index page

Reference django-registration, registration and login form on index page together, did I do it right?

OTHER TIPS

Don't know that it is the best way of going about it, but I suppose you could go into django-registration (registration.auth_urls.py) and edit the login url so that it is r'^$' instead of r'^login/$'. This generally isn't the best practice, but it should work.

If you want your actual www.example.com to be login page just do this:

url(r'^$', include('registration.backends.default.urls')),

If you want your login page have its own page then do this:

url(r'^/login/$', include('registration.backends.default.urls')),

So when you go to www.example.com/login it will go to login page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top