2017-10-21 19 views
3

J'utilise la dernière version de django et python 3, Lorsque je me connecte, je reçois le message d'erreur ci-dessous.django login() prend 1 argument positionnel mais 2 ont été donnés

connexion django() prend 1 argument de position, mais 2 ont reçu

S'il vous plaît trouver le code pour moi de connexion ci-dessous.

from django.shortcuts import render, get_object_or_404,redirect 
from django.contrib.auth.models import User 
from django.contrib.auth import authenticate, login 
from authentication.forms import LoginForm, ForgottenPasswordForm, ResetPasswordForm 
from authentication.functions import send_user_reset_password_link, resend_password_reset_link 
from authentication.models import ResetPassword 
# Create your views here. 

def login(request): 
    error_message = None 
    heading = 'Login Form' 
    if request.method == 'POST': 

     form = LoginForm(request.POST) 
     if form.is_valid(): 

      username = form.cleaned_data['username'] 
      password = form.cleaned_data['password'] 
      remember_me = form.cleaned_data['remember_me'] 

      user = authenticate(request,username=username, password=password) 

      if not request.POST.get('remember_me', None): 
       #request.session.set_expiry(0)   
      if user is not None: 
       login(request, user) 
       return redirect('property_index',user.id) 
      # A backend authenticated the credentials 
      else: 
       error_message = 'No login credentials found' 
      # No backend authenticated the credentials 

    form = LoginForm() 
    return render(request,'authentication/forms/login.html',{ 
     'form':form, 
     'error_message':error_message, 
     'heading':heading 

     }) 
+2

vous substituez 'login' en définissant une nouvelle fonction' login'. –

+0

Appelez votre avis autre chose. –

Répondre

4

changement importation

from django.contrib.auth import authenticate, login as dj_login 
#             ^^^^^^^^ 

et utiliser

dj_login(request, user)