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
59
votes
13 answers

Django: Populate user ID when saving a model

I have a model with a created_by field that is linked to the standard Django User model. I need to automatically populate this with the ID of the current User when the model is saved. I can't do this at the Admin layer, as most parts of the site…
seanf
56
votes
3 answers

Django-AttributeError 'User' object has no attribute 'backend' (But....it does?)

In order to sign users in after registering them, I manually set the user.backend property. It normally works in my views. In this instance, I'm trying to register the user via AJAX. It is raising an AttributeError. Here is my code: def…
Ben
  • 15,010
  • 11
  • 58
  • 90
50
votes
5 answers

Enforcing password strength requirements with django.contrib.auth.views.password_change

We have a Django application that requires a specific level of password complexity. We currently enforce this via client-side JavaScript which can easily be defeated by someone who is appropriately motivated. I cannot seem to find any specific…
jslatts
  • 9,307
  • 5
  • 35
  • 38
49
votes
4 answers

TypeError: login() takes 1 positional argument but 2 were given

I have written a login view using build-in auth ,django auth.login() gives above error my code with error code o 500 from rest_framework.response import Response from rest_framework import status from rest_framework.decorators import api_view from…
sabari rangan
  • 659
  • 1
  • 6
  • 14
47
votes
6 answers

Why second user login redirects me to /accounts/profile/ url?

I am using Django built in view for user login: url(r'^user/login/$', 'django.contrib.auth.views.login', {'template_name': 'users/templates/login.html'}, name='user-login'), After login when I goto user/login again I can login second time. I submit…
Codium
  • 3,200
  • 6
  • 34
  • 60
46
votes
4 answers

Putting a django login form on every page

I'd like the login form (AuthenticationForm from django.contrib.auth) to appear on every page in my site if the user is not logged in. When the user logs in, they will be redirected to the same page. If there is an error, the error will be shown on…
asciitaxi
  • 1,369
  • 1
  • 16
  • 16
45
votes
3 answers

How to deploy an HTTPS-only site, with Django/nginx?

My original question was how to enable HTTPS for a Django login page, and the only response, recommended that I - make the entire site as HTTPS-only. Given that I'm using Django 1.3 and nginx, what's the correct way to make a site HTTPS-only? The…
John C
  • 6,285
  • 12
  • 45
  • 69
42
votes
3 answers

django - set user permissions when user is automatically created using get_or_create

Django 1.5, python 2.6 The model automatically creates a user under certain conditions: User.objects.get_or_create(username=new_user_name, is_staff=True) u = User.objects.get(username=new_user_name) u.set_password('temporary') In addition to…
billrichards
  • 2,041
  • 4
  • 25
  • 35
40
votes
16 answers

Log in user using either email address or username in Django

I am trying to create an auth backend to allow my users to log in using either their email address or their username in Django 1.6 with a custom user model. The backend works when I log in with a user name but for some reason does not with an email.…
user3282276
  • 3,674
  • 8
  • 32
  • 48
38
votes
5 answers

Change Django ModelChoiceField to show users' full names rather than usernames

I have a form in my Django app (not in admin) that allows staff members to select a user from a dropdown. forms.ModelChoiceField(queryset = User.objects.filter(is_staff=False), required = False) The problem is that the dropdown shows users by…
Adam
  • 43,763
  • 16
  • 104
  • 144
38
votes
2 answers

django-object-permissions Vs django-guardian Vs django-authority

I've found 3 row-level permission solutions for Django 1.2+ django-object-permissions django-guardian django-authority Could someone tell if there is any recommended more than the others, what are their main differences, etc.?
Akasha
  • 2,162
  • 1
  • 29
  • 47
36
votes
8 answers

How to get user permissions?

I want to retrieve all permission for user as list of premission id's but: user.get_all_permissions() give me list of permission names. How to do it?
Nips
  • 13,162
  • 23
  • 65
  • 103
35
votes
4 answers

How to use TokenAuthentication for API in django-rest-framework

I have a django project, using django-rest-framework to create api. Want to use token base authentication system so api call for (put, post, delete) will only execute for authorized user. I installed 'rest_framework.authtoken' and created token for…
Peter
  • 1,023
  • 4
  • 18
  • 23
35
votes
4 answers

AttributeError: 'Manager' object has no attribute 'get_by_natural_key' error in Django?

I am using Django '1.5c1'. I have this line in my settings.py: AUTH_USER_MODEL = 'fileupload.galaxyuser' Here's my Galaxyuser model: class GalaxyUser(models.Model): id = models.IntegerField(primary_key=True) create_time =…
pynovice
  • 7,424
  • 25
  • 69
  • 109
34
votes
3 answers

NoReverseMatch Error

I keep getting this error for the django login system. Here is part of my urls.py: (r'^contractManagement/login', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), The exact error I am getting: Exception Type:…
Dean
  • 8,668
  • 17
  • 57
  • 86