我刚用Django创建了一个登录,但它不想工作。脚本应重定向到开始.html如果用户正确登录。但是Django只需重新加载页面,在url中写入用户名和passwort。在
在视图.py在
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login
from django.views.generic import View
class Index(View):
def get(self, request):
return render(request, "index.html")
def user_login(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('^start/')
else:
return HttpResponseRedirect('^err/')
else:
print ("Invalid login details")
return HttpResponseRedirect('^impressum/')
在网址.py项目的:
^{pr2}$这怎么了?在
完整代码:https://github.com/Croghs/stuport
谢谢你的帮助,很抱歉英语不好
低腰
将
<form type="post">
更改为<form method="post">
索引.html. 在基于类的视图无法识别“用户登录”方法。它应该被称为“邮政”。在
相关问题 更多 >
编程相关推荐