M
M
maestro072017-03-31 07:40:41
Django
maestro07, 2017-03-31 07:40:41

How to do django authorization?

Authorisation Error. When I authorize in the adminpanel through the super user, the username is displayed. and when I try to log in through a registered user (not in the adminpanel), it does not work.
html
3143e3e433434043adc66dd2f58619d5.png
url.py

from django.conf.urls import url
from . import views
from django.conf import settings
from django.contrib.auth.views import logout

urlpatterns = [
    url(r'^index/$', views.index, name='index'),
    url(r'^login/$', views.login, name='login'),
    url(r'^registration/$', views.registration, name='registration'),
    url(r'^logout/$', logout, {'next_page': "/main/login"}, name='logout')
]

views.py
def login(request):
    template = "main/login.html"
    params = dict()
    if request.method == "POST":
        email = request.POST.get("email", "")
        password = request.POST.get("password", "")
        print email
        print password
        user = authenticate(username=email, password=password)
        print user
        if user is None:
            print 1
            template = "main/index.html"
            return render(request, template, params)  

    return render(request, template, params)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FeNUMe, 2017-03-31
@FeNUMe

from django.contrib.auth import authenticate, login

user = authenticate(username=username, password=password)
if user is not None:
    login(request, user)

Read on the docks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question