我正在写一个应用程序,包括用户注册和登录功能。成功登录/注册操作后,用户将被重定向到user.html
现在,整个HTML文本显示为URL参数,这将引发错误404
用于视图处理的我的视图代码:
def index(request):
return render(request, "app/index.html")
def user(request):
return render(request, "app/user.html")
def userLogin(request):
print "Loggin In!"
loginUser = authenticate(username = request.POST["username"], password = request.POST["password"])
print loginUser.username
print loginUser.is_staff
if loginUser is not None:
if loginUser.is_active:
login(request, loginUser)
return HttpResponseRedirect(reverse(user))
以及我的网址:
^{pr2}$重定向时,将显示以下消息:
Django tried these URL patterns, in this order:
^admin/
^app/ ^$ [name='index']
^app/ ^user/$
^app/ ^registerNewUser/$
^app/ ^userLogin/$
The current URL, app/<html><head><title>User Landing Page</title><link rel = "stylesheet" type = "text/css" href = "/static/css/jquery-ui.min.css" ><link rel = "stylesheet" type = "text/css" href = "/static/css/main.css"><script type = "text/javascript" src = "/static/js/jquery.js"></script><script type = "text/javascript" src = "/static/js/jquery-ui.min.js"></script><script type = "text/javascript" src = "/static/js/jquery.cookie.js"></script><script type = "text/javascript" src = "/static/js/csrfSetup.js"></script></head><body>User is logged</body></html>, didn't match any of these.
为了在成功登录时呈现HTML,我需要做些什么?在
请再次阅读django的文档和reverse方法:
在你的视图.py在
在你的网址.py在
^{pr2}$这是对我有效的解决方案。它包括使用}。在
reverse()
和{具体来说
结合以下
^{pr2}$urls.py
配置在成功登录或注册后,重定向到相关页面。在
相关问题 更多 >
编程相关推荐