user1050619
user1050619

Reputation: 20856

Django form redirection failing--page Not found error

I have a login form, which needs to be re-directed to the main page once the login is performed but for some reason I get the page not found error & it gets re-directed to the below page instead of main page.

http://127.0.0.1:8000/accounts/profile/

Here is the code,

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

Upvotes: 6

Views: 5346

Answers (1)

Evan Porter
Evan Porter

Reputation: 2977

Change the LOGIN_REDIRECT_URL value in settings.py to you main page's URL. It defaults to /accounts/profile/ if it doesn't exist.

You can also read the LOGIN_REDIRECT_URL documentation.

Upvotes: 12

Related Questions