Django built-in login view and errors -
i'm using django.contrib.auth.views.login and
.logout
views. handy, worked out of box, deploy again aaa+ etc.
the problem arises since i'm not using separate login page, rather have login box in every page (unless user logged in, of course). , so, when username/password combination wrong, error. of these 3 paths should choose?
- there secret way redirect next not on success on error. if so, please tell me!
- i write own login view, putting use django's message system in meanwhile
- i write login page (well, it's missing template) can exploit full awesomeness of django auth system.
one of possible solutions (first + third choices in list):
- you have provide special login page (that define
registration/login.html
) , non loged in user each normal page has login form; - if user logins (this logic handled in
django.contrib.auth.views.login
):- for normal page: redirect user page loged in;
- for login page: if there
next
param, redirect there, else redirect main page;
- if user fails login: redirect (or redraw) login page errors provided;
- if user loged in: normal page provides link logout (special page still there in case if user want's re-login or login through account).
in normal pages, login form should have <input type="hidden" name="next" value="{{ request.path }}" />
.
in project settings:
# in settings.py login_url = '/login' # should coinside url pattern of login view logout_url = '/logout' # same logout view login_redirect_url = '/' # url main page
n.b.: don't use django's buildin logout view instead use own: same logout post requests. disallows users logout <img src='my_site/logout' />
malicious code.
Comments
Post a Comment