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
17
votes
6 answers

Django - Override admin site's login form

I'm currently trying to override the default form used in Django 1.4 when logging in to the admin site (my site uses an additional 'token' field required for users who opt in to Two Factor Authentication, and is mandatory for site staff). Django's…
TC Fox
  • 980
  • 4
  • 13
  • 25
16
votes
5 answers

How can I set a minimum password length when using the built-in Django auth module?

I’m implementing authentication in a Django site using the built-in auth module, including the built-in UserCreationForm. I’d like to set a minimum length for passwords. However, I can’t find any documentation on how to do this. Can I configure the…
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
16
votes
1 answer

self.model() in django custom UserManager

So, I'm fairly new to Django. Notwithstanding the fact that my code works after following the Django docs 'Customizing authentication in Django', I don't get how the self.model(...) in their example actually works, where it comes from and how it…
16
votes
1 answer

How does default_token_generator store tokens?

I recently built a Django-based authentication system using a tutorial. Within this System I created a token within a forms.py. This Token is then send (as a link) in an activation activation mail. from django.contrib.auth.tokens import…
Xen_mar
  • 8,330
  • 11
  • 51
  • 74
16
votes
7 answers

What is the opposite of @login_required decorator for Django views?

If I want to make sure that a view is listed as having public access, is there a decorator equivalent to @public_access which would be the opposite of @login_required and make it clear that the view should be publicly accessible always? One use case…
MikeN
  • 45,039
  • 49
  • 151
  • 227
16
votes
4 answers

Django - CSRF token missing or incorrect

I just updated my django to 1.4. But I am getting the following error when I try to submit my login form: Forbidden (403) CSRF verification failed. Request aborted. Reason given for failure: CSRF token missing or incorrect. In my…
Thomas
  • 2,256
  • 6
  • 32
  • 47
15
votes
3 answers

Object of type 'AuthToken' is not JSON serializable

I'm getting the above error when creating token, here's the code: from rest_framework import generics, permissions from rest_framework.response import Response from knox.models import AuthToken from .serializers import UserSerializer,…
15
votes
1 answer

Authenticate in Django without a database

I have a Django app that gets it's data completely from apis. so I don't have to use database. Session data is stored on signed cookies. I tried to code a custom User model and a custom auth backend like on the docs, but I get the following…
gosling_
  • 151
  • 1
  • 8
15
votes
3 answers

What more do I need to do to have Django's @login_required decorator work?

I am trying to use Django's account system, including the @login_required decorator. My settings.py file includes django.contrib.auth and I have done a syncdb. Page not found (404) Request Method: GET Request URL: …
Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
15
votes
4 answers

Multiple Django apps, shared authentication

Two answers to this question, depending on whether sharing is across different sites or different subdomains Second answer: Multiple Django apps, shared authentication A user goes to site1.com and logs in. Now, if he goes to site2.com, then he…
user984003
  • 28,050
  • 64
  • 189
  • 285
15
votes
5 answers

(Django) Sharing authentication across two sites that are on different domains

I have two sites say foo.com and bar.com and are both Django based. Primary registration occurs on foo.com (I'd like the main user db to be here) and I'd like for three things to happen: 1) User that logs in to foo.com is automatically able to…
Terry J
  • 1,051
  • 2
  • 10
  • 9
15
votes
2 answers

Django save model with anonymous user

I have a Django model: class Project(models.Model): user = models.ForeignKey(User) zipcode = models.CharField(max_length=5) module = models.ForeignKey(Module) In my views.py: def my_view(request): ... project =…
Darwin Tech
  • 18,449
  • 38
  • 112
  • 187
15
votes
6 answers

How can make Django permission_required decorator not to redirect already logged-in users to login page, but display some message

How can make Django permission_required decorator not to redirect already logged-in users to login page, but display some message like Insufficient permissions? Thank you.
dsmilkov
  • 480
  • 1
  • 4
  • 9
14
votes
4 answers

Django: any way to avoid querying for request.user on every request?

For my website pretty much every page has a header bar displaying "Welcome, ABC" where "ABC" is the username. That means request.user will be called for every single request resulting in database hits over and over again. But once a user is logged…
Continuation
  • 12,722
  • 20
  • 82
  • 106
14
votes
2 answers

How to login a user during a unit test in Django REST Framework?

This is my DRF view: @api_view(['GET']) @permission_classes([IsAuthenticated]) def check_user(request): user = request.user # use user object here return JSONResponse({}) And this is my unit test for said view: class…