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

  1. you have provide special login page (that define registration/login.html) , non loged in user each normal page has login form;
  2. 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;
  3. if user fails login: redirect (or redraw) login page errors provided;
  4. 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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -