Questions tagged [django-authentication]

django-authentication refers to the built-in auth module for authentication & authorization that can be extended.

django-authentication refers to the built-in auth module for authentication & authorization that can be extended. It handles user accounts, groups, permissions and cookie-based user sessions.

See documentation.

1888 questions
32
votes
4 answers

How can I detect multiple logins into a Django web application from different locations?

I want to only allow one authenticated session at a time for an individual login in my Django application. So if a user is logged into the webpage on a given IP address, and those same user credentials are used to login from a different IP address…
MikeN
  • 45,039
  • 49
  • 151
  • 227
31
votes
2 answers

Override default get_absolute_url on User objects?

I'm trying to make a generic table for listing django_tables objects. I've got everything working, except that the get_absolute_urls() on my User objects returns: /users// While I could create this URL, it doesn't match with the rest of…
Jack M.
  • 30,350
  • 7
  • 55
  • 67
29
votes
10 answers

How can I not use Django's admin login view?

I created my own view for login. However if a user goes directly to /admin it brings them to the admin login page and doesn't use my custom view. How can I make it redirect to the login view used for everything not /admin?
Bufke
  • 3,195
  • 3
  • 28
  • 28
29
votes
1 answer

How do I setup a unit test user for django app? The unit test can't login

I've enabled login authentication for my django app. Unit tests for views are not working because they get stuck at the login page. Setting a breakpoint immediately after the view's response is returned and using print response.content results…
dolphus333
  • 1,232
  • 1
  • 13
  • 18
29
votes
3 answers

custom django-user object has no attribute 'has_module_perms'

My custom user model for login via email: class MyUser(AbstractBaseUser): id = models.AutoField(primary_key=True) # AutoField? is_superuser = models.IntegerField(default=False) username = models.CharField(unique=True,max_length=30) …
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
29
votes
2 answers

Django user get_all_permissions() is empty while user_permissions is set

I added some permissions to a user via the admin interface. From some reason all the perm functions fail, e.g >>> user.get_all_permissions() set([]) But accessing the table directly, works: >>> user.user_permissions.all() (list of permissions as…
Boris
  • 3,163
  • 5
  • 37
  • 46
28
votes
11 answers

Django: How can I apply the login_required decorator to my entire site (excluding static media)?

The example provides a snippet for an application level view, but what if I have lots of different (and some non-application) entries in my "urls.py" file, including templates? How can I apply this login_required decorator to each of…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
26
votes
3 answers

Django create custom UserCreationForm

I enabled the user auth module in Django, however when I use UserCreationForm it only asks for username and the two password/password confirmation fields. I also want email and fullname fields, all set as required fields. I've done this: from…
Joaquin McCoy
  • 425
  • 2
  • 7
  • 16
26
votes
2 answers

NoReverseMatch while rendering: Reverse for ''django.contrib.auth.views.login''

I'm using Django's authentication, and in the login.html template, the following statement is generating an error: {% url 'django.contrib.auth.views.login' %} TemplateSyntaxError at /login Caught NoReverseMatch while rendering: Reverse for…
Nate Reed
  • 6,761
  • 12
  • 53
  • 67
25
votes
5 answers

How do I use the The login_required decorator in my URL?

I want to check that the user is authorized for certain URLs. I'm using generic views. The docs here say the login_required can be passed as an optional arguments but I'm not sure. Something like this maybe: (r'^$', 'archive_index', link_info_dict,…
darren
  • 18,845
  • 17
  • 60
  • 79
25
votes
5 answers

Django - user permissions to certain views?

From the admin I see that you can allocate permissions to a user or a user group to :allow add, change or delete data from a model. That is great, but I also need to allow a user or a user group to access or not a group of views. I have certain…
avatar
  • 12,087
  • 17
  • 66
  • 82
25
votes
5 answers

Auto register Django auth models using custom admin site

I implemented authentication management using Django auth with the default admin site but then I wanted to use my own AdminSite to rewrite some behaviors: class OptiAdmin(admin.AdminSite): site_title = "Optimizer site's admin" #...Other…
25
votes
3 answers

What's the difference between authenticate and login?

Documentation: https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.login When you’re manually logging a user in, you must call authenticate() before you call login(). authenticate() sets an attribute on the User noting…
User
  • 23,729
  • 38
  • 124
  • 207
24
votes
6 answers

Most optimized way to delete all sessions for a specific user in Django?

I'm running Django 1.3, using Sessions Middleware and Auth Middleware: # settings.py SESSION_ENGINE = django.contrib.sessions.backends.db # Persist sessions to DB SESSION_COOKIE_AGE = 1209600 # Cookies last 2 weeks Each…
Dave
  • 12,408
  • 12
  • 64
  • 67
24
votes
1 answer

Django authentication - wrong redirect url to login page

When a user is not logged I'm trying to enter areas of site for authenticated users only I should be redirected to my login site with ?next= and here my LOGIN_REDIRECT_URL from settings. But instead of /users/login in my address bar /accounts/login…
tom_pl
  • 425
  • 2
  • 9
  • 16