我在寫一個包含用戶註冊和登錄功能的應用程序。登錄成功/註冊操作後,用戶現在將被重定向至user.html
Django重定向 - 爲什麼頁面HTML顯示爲URL參數?
,整個HTML文本顯示爲一個URL PARAM,這是引發錯誤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))
和我的網址:
urlpatterns = patterns("",
url(r'^$', views.index, name = "index"),
url(r'^user/$', views.user),
url(r'^registerNewUser/$', views.registerNewUser),
url(r'^userLogin/$', views.userLogin),
)
在重定向,這是顯示消息:
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,我需要做些什麼?
你幾乎是正確的,檢查我的答案爲我的解決方案。感謝提示! – Jason