我有一个登录表单,一旦登录执行需要重定向到主页面但由于某种原因我得到页面找不到错误&它被重定向到下面的页面而不是主页面.
http://127.0.0.1:8000/accounts/profile/
这是代码,
的login.html
<html> <head> <title>Django Bookmarks - User Login</title> </head> <body> <h1>User Login</h1> {% if form.errors %} <p>Your username and password didnt match.Please try again.</p> {% endif %} <form method="post" action="."> <p>label for="id_username">Username:</label> {{ form.username }}</p> <p>label for=id_password>Password:</label> {{ form.password}}</p> <input type="hidden" name="next" value="/" /> <input type="submit" value="login" /> </form> </body> </html>
url.py
urlpatterns = patterns('',(r'^admin/',include(admin.site.urls)),(r'^$',main_page),(r'^user/(\w+)/$',user_page),(r'^login/$','django.contrib.auth.views.login'),(r'^logout/$',logout_page),(r'^site_media/(?P<path>.*)$','django.views.static.serve',{'document_root':site_media}),(r'^register/$',register_page),(r'^volunteer/$',volunteer_page),(r'^save/$',bookmark_save_page),)
解决方法
将settings.py中的LOGIN_REDIRECT_URL值更改为主页面的URL.如果它不存在,则默认为/ accounts / profile /.