Django表单重定向失败 - 页面未找到错误

时间:2012-03-29 15:53:02

标签: django

我有一个登录表单,一旦执行登录需要重定向到主页面但由于某种原因我得到了找不到页面的错误&它被重定向到下面的页面而不是主页面。

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),
)

1 个答案:

答案 0 :(得分:12)

LOGIN_REDIRECT_URL中的settings.py值更改为主页的网址。如果不存在,则默认为/accounts/profile/

您还可以阅读LOGIN_REDIRECT_URL documentation