2

I have install Django admin & created some active user & group by admin page. I need to do login form & views, which will check if user is valid or not do task in the basis of permission. I have tried following steps.(for reference)

  1. Copied admin login.html for testing & paste it foo_project/templates/registration/login.html

  2. Added in urls.py

    from django.contrib.auth.views import login

    url(r'^login/', login),

Now by running 127.0.0.1:8080/login When I am entering valid user-name & password its trying to open /accounts/profile/ & it's not found in urls.py. And if I am entering invalid username or password its doing nothing.

So I simple need to link a page if login successful(user created by admin) & check which type of permission & group he is.Admin created auth_user table in my db.sqlite3

I am new to Django & using version 1.6.

I read document & tried built-in login() in views.py. Got unsuccess. Is there any built-in for above need. Please describe in depth if possible.

Swagat
  • 617
  • 5
  • 16

1 Answers1

1

In settings.py create this entry:

LOGIN_REDIRECT_URL = "your_redirect_url"

The user will be redirected to this page after login. Then on the url you will create which will respond to "your_redirect_url" (and should be defined somewhere in your urls.py), you can check the permissions, or groups. For more help about checking permissions, groups, you can find it here.

The login_required decorator can be really useful on implementing your view for your "redirect_url", because you don't want anonymous users accessing to this part of the site, right?

avenet
  • 2,894
  • 1
  • 19
  • 26
  • 1
    Thanks @avenet for reply... But it still redirect me to /acounts/profile – Swagat Jan 09 '14 at 14:12
  • This is a admin login file..What to do if I create custom login file ..i.e.what objects should be same to connect with auth_user – Swagat Jan 09 '14 at 14:24
  • What do you mean with login file? – avenet Jan 09 '14 at 14:27
  • yes & where acounts/profile..Am i have to install or import something – Swagat Jan 09 '14 at 14:29
  • I think I'm getting your point, do you need to extend the Django User with your profile data? – avenet Jan 09 '14 at 14:32
  • yes & I followed and done Documentation till admin add user..So if i left something which is needed to do for user authentication & in urls.py..Sorry if long convertation – Swagat Jan 09 '14 at 14:36
  • Please check this: http://stackoverflow.com/questions/44109/extending-the-user-model-with-custom-fields-in-django – avenet Jan 09 '14 at 14:43
  • I am asking this B'coz generaly by-default acounts/profile should exist somewhere should work.Right? Or every non staff user should treated like this – Swagat Jan 09 '14 at 14:44
  • No, in Django it works this way: Django provides the most useful fields for users, if you need more than that, there are two ways: the first is creating an extra table and the other one involves extending the User model, it depends on what you need. – avenet Jan 09 '14 at 15:08