Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django form redirection failing--page Not found error

Tags:

django

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),
)
like image 449
user1050619 Avatar asked Mar 29 '12 15:03

user1050619


1 Answers

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.

like image 178
Evan Porter Avatar answered Sep 19 '22 15:09

Evan Porter