Can we use the / admin login page in django for our own use?

Can I use the login page, available at: /admin for non-employee users, to login? I use the following settings in the django settings file:

 LOGIN_URL = '/admin/' LOGIN_REDIRECT_URL = '/' 

When I log in, it does not redirect me to the root folder. Am I doing it right?

Note. I am using the @login_required decorator in my view.

Edit

He registers me on the admin site using this URL: http://127.0.0.1:8000/admin/?next=/

+7
source share
2 answers

Non-employee employees cannot log in through Administrator View, so you cannot.

There is a Django view that does exactly what you need: django.contrib.auth.views.login

You can easily add it to your urlconf :

 from django.contrib.auth.views import login urlpatterns = ('', #snip url(r'^login/$', login) ) 

Check the documentation to see how you can customize its behavior: https://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-logged-in-users

You just need to define a template for the view used, by default it should be located in registration/login.html , but this can be overridden.

+10
source

With Django 1.6, I was able to use my own django admin login template with the following setup. Then, when I open '/', it redirects me to the login screen, and after logging in, it sends me back to '/'

settings.py

 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'core', 'south', ) LOGIN_URL = '/login' 

urls.py

 from django.conf.urls import patterns, include, url from django.contrib import admin from django.contrib.auth.views import login admin.autodiscover() urlpatterns = patterns( '', url(r'^', include('core.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^login/$', login, {'template_name': 'admin/login.html'}) # I didn't create this 'admin/login.html' template # Django will use the one from the admin application ;-) ) 

core /urls.py

 from django.conf.urls import patterns, url urlpatterns = patterns( 'core.views.web_views', url(r'^$', 'home'), ) 

core /view/web_views.py

 from django.shortcuts import render_to_response from django.template.context import RequestContext __author__ = 'tony' from django.contrib.auth.decorators import login_required @login_required def home(request): return render_to_response('home.html', {}, context_instance = RequestContext(request)) 
+7
source

All Articles