0
我有點新的django和工作的用戶處理。 現在我已經整理了一切,它的工作原理很好,除了當用戶輸入無法登錄的數據時。 未顯示錯誤消息。 我想知道是否會有一個更容易/更好的方法來解決這個問題,然後把我的所有視圖中的空變量,除了無效登錄。 (存儲在消息)django重定向變量索引
我auth_view:
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
#returns None if not correct
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect(reverse('index'))
else:
invalid_login = "ErrorMessage"
return HttpResponseRedirect(reverse('index')
指數就是在這一刻:
def index(request):
return render(request, 'index.html')
我怎麼能解決這個問題? (或者你會建議我只是到處都是多餘的VAR接近它)
隨着親切的問候 漢斯
的UserAuthenticationForm一個登錄表單,一些驗證也許是爲了? –