Questions tagged [django-authentication]

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

django-authentication
Filter by
Sorted by
Tagged with
185 votes
7 answers
351k views

How to get the currently logged in user's id in Django?

How to get the currently logged-in user's id? In models.py: class Game(models.model): name = models.CharField(max_length=255) owner = models.ForeignKey(User, related_name='game_user', ...
0 votes
1 answer
150 views

Share Custom User model between two Django projects (same db)

i have two Django project, sharing the same DB (postgres) The first one is an onboarding project for the users where i store the user data. The second one is the project where all the entities related ...
0 votes
1 answer
20 views

Registration system not working in Django

Hello, I have created a user registration system, but when I fill in the information on the registration page and click on registration, no user is created and only the same form is displayed on the ...
0 votes
1 answer
33 views

Problems logging in with email in Django admin

I have followed a tutorial to enable user login in django through mail, but after doing it and having the app running, the logind admin view does not recognize my username and/or password, I leave an ...
0 votes
0 answers
22 views

Django inbuilt Auth not logging me in despite successfully registering the user

i would like to login after registering a user that is saved using my customuser model that exends abstractuser. after registering the user, i redirect them to the login page. and when i try to login ...
0 votes
1 answer
39 views

Django.auth.authenticate not authenticating user

I am creating an app, and I am trying to manually create the login page so I can add some things that I can't add using the default Django authentication pages. This is what my view looks like: def ...
2 votes
4 answers
8k views

'function' object has no attribute 'user' error in Django?

I get this error when I use: @login_required('/login_backend/') in my views. I am using Django 1.5. My user model is: class User(AbstractBaseUser): #id = models.IntegerField(primary_key=True) ...
0 votes
1 answer
49 views

Least painful way of not using int4 as primary key in Django user models?

I'm new to Django, and upon running the first migration, it seems the primary key ID of the auth_users table is an int4. Looking through the docs, it seems if I use any kind of custom User model, for ...
1 vote
1 answer
97 views

request.user showing "AnonymousUser" in django classview dispatch method but not in "get_object" method

class ProductViewSet(viewsets.ReadOnlyModelViewSet): authentication_classes = [JWTAuthentication] permission_classes = [IsAuthenticated] # @method_decorator(custom_ratelimit) ...
-1 votes
2 answers
557 views

Django AuthenticationForm is not working this give error name 'UsernameField' is not defined

This is my code class LoginForm(AuthenticationForm): username = UsernameField(label='username', widget=forms.TextInput(attrs={'autofocus':True,'class':'form-control'})) password = forms....
0 votes
0 answers
77 views

TypeError at /saml2/ls/post/ Not a logout_response

I am trying to setup django with saml2 for sso with okta. In okta settings I have Single Logout URL: http://localhost:8000/saml2/ls/post/ SP Issuer : http://localhost:8000/saml2/metadata/ as per the ...
0 votes
1 answer
201 views

Django Authentication Form not working properly

I am trying to create a very basic login system (just to grasp Django's authentication system, nothing fancy). Thing is, when I use the following code (i.e. don't validate authentication form ...
1 vote
1 answer
44 views

When using custom AuthBackend, unable to use request.user.is_authenticated or @login_required decorator

Firstly I'm coming from a PHP background and new to Django. And I'm trying to upgrade a webapp from a PHP framework to Django, keeping the database unchanged. The built-in authentication in Django is ...
0 votes
2 answers
987 views

Django, how to do two-factor authorization via email?

I have a website and I have already redefined the user model, made authorization/registration via email. Now I want to do authorization when a user enters a username, password and a confirmation code ...
0 votes
1 answer
140 views

How can Django keep an API user logged in without a browser or return token?

https://github.com/mugartec/django-ninja-auth/blob/bf36b4583a37213001131678d5ecda07f92ba2f6/ninja_auth/api.py#L33 It doesn't return any token, so how to does it identify them post-login for subsequent ...
0 votes
0 answers
84 views

How to delete session data from django_session table when user closes browser

I am using Django Session Authentication. I set SESSION_EXPIRE_AT_BROWSER_CLOSE = True as i want users to login each time they close the browser. All works fine user closes browser session got deleted ...
0 votes
0 answers
100 views

apache reverse proxy with django authentication and geoserver

i want to use django authentication before redirectiong to geoserver using apache reverse-proxy, i can Redirect to login page but after submitting the /login/?next=/geoserver return me to first page ...
0 votes
0 answers
46 views

Django Two seperate user profile regsitration, login and logout view funciton implementation failed

I need to develop a different e-commerce project with the Django Rest Framework and ReactJS integrated through Axios. But I wonder how to implement two separate users like farmers as a vendor and ...
8 votes
2 answers
8k views

How to disable django.contrib.auth completely?

Because I'm using my own authentication and authorization system (with my own User/Permission model), I would like to completely disable this standard app from Django. I've tried removing the ...
0 votes
1 answer
484 views

nginx auth_request: How to add GET parameters after successful authentication

Sorry this is probably a rather simple question, but I can find nginx rather confusing. I am using the auth_request module in nginx to authenticate users with Django to use a Flask app. If the ...
1 vote
3 answers
373 views

Python/Django: What steps i have to follow in order to properly redirect a user with {{ next }}?

For hours i'm trying to figure it out without result. {{ next }} variable is not working for me (i mean it is empty), but works this way {{ request.REQUEST.next|urlencode }}. However doesn't redirect ...
0 votes
0 answers
52 views

django login url with param

a third party authentication requires api must to be called in the index view. for example, my domain is zzd.com, then they only provide api to zzd.com, which means we cannot have route specified for ...
0 votes
0 answers
114 views

I have installed and configured django-allauth-2fa. How to create a button for user to apply 2fa?

all. I have installed and configured django-allauth-2fa following this documentation: https://django-allauth-2fa.readthedocs.io/en/latest/installation/. Can anyone tell me what to do next to apply to ...
0 votes
1 answer
199 views

Is it bad written my custom authentication backend in Django?

I'm trying to implement a custom authentication backend in Django, mi custom Auth model and my custom user creation form works ok, but when I'm try to login using my custom authentication backend, it ...
10 votes
4 answers
9k views

In Django admin, how to filter users by group?

It gives you filter by staff status and superuser status, but what about groups?
1 vote
1 answer
381 views

Django register form not showing up on admin users when submitted

I want to create a register and login but when I create account in http://127.0.0.1:8000/register/ it doesn't show in admin (http://127.0.0.1:8000/admin/auth/user/) views.py from django.contrib.auth....
7 votes
2 answers
14k views

Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

Full Error: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django....
0 votes
2 answers
1k views

Django's manage.py createsuperuser gives error OperationalError: 'no such table'

I am working on my Final Year Project. I wanted to extend the default User model that Django provides in order to add some more attributes. I added following code in my models.py class User(...
1 vote
1 answer
30 views

Overriding LoginView has no effect in the registration template

I tried to add some classes to my projects login template via overriding the LoginView as described here, but I seem to miss something obvious: views.py: class CustomLoginView(LoginView): # ...
0 votes
1 answer
38 views

How can I do authentication on the site and the built-in Users model and my own Employer Django?

I ran into a problem I am making a job search site on Django, I have the following logic: Authorization and authentication of ordinary job seekers using Django's built-in model - User Also separate ...
1 vote
1 answer
862 views

Cors error happening on a simplejwt authenticated webpage

I have used simplejwt in my code and I also have added django-cors-headers to my project to allow frontend development. the problem is that I have 2 APIs that need authentication to allow users to ...
0 votes
0 answers
93 views

Django allauth: Multiple user registration with email-only authentication causing UNIQUE constraint error

I have an issue with a django allauth project I typed that in settings.py to disable username field and use email address SOCIALACCOUNT_QUERY_EMAIL = True ACCOUNT_LOGOUT_ON_GET= True ...
3 votes
2 answers
2k views

Django password field custom class

I would like to render the password field with a custom class, so I tried this: from django.contrib.auth import get_user_model from django.db import transaction User = get_user_model() class ...
1 vote
1 answer
153 views

Authenticate works but login does not. It's stuck on pending

The issue is as explained in the title. I am able to create and authenticate users through forms or the cli but once the user/patient object is passed to the login(request, user) function, the entire ...
0 votes
0 answers
101 views

Password change form URL broken

I am making a portfolio/blog. I have created a edit profile page using django and bootstrap available tools. The change edit profile form comes with a hyperlink that says click this form to change ...
-1 votes
1 answer
38 views

How to redirect to 2 different app in django, base on the user group from single login url

I have the following scenario: My project has two different Django apps, Dashboard and FrontView, with different user groups. Current login urls are as below: http://127.0.0.1:8000/dashboard/login ...
104 votes
8 answers
70k views

Django's self.client.login(...) does not work in unit tests

I have created users for my unit tests in two ways: 1) Create a fixture for "auth.user" that looks roughly like this: { "pk": 1, "model": "auth.user", "fields": { ...
0 votes
0 answers
47 views

New users which are created by django-windowsauth upon first login are saved as DOMAIN\USERNAME, How can I change the default to USERNAME?

I'm creating a website with django for the first time and I needed the users to be authenticated with Active Directory so I used django-windowsauth package, but now when someone logs in for the first ...
1 vote
0 answers
42 views

How to restrict user access to prevent visiting other user profiles

In my app, no anonimus uzer can switch to another profile, he only should know the pers_id. How can I forbid doing this? my views.py: @login_required def home(request): pers_id = request.GET.get('...
3 votes
1 answer
306 views

Django module not found error: email verification

I'm new to python and Django so sorry in advance if I'm missing something obvious. I'm trying to install the module 'django-email-verification' following this tutorial to add email verification to my ...
2 votes
3 answers
7k views

How to forcefully log out a user when user closes tab or browser on website built on django2.0

I used built-in login logout functionality by Django using Django authentication, this is the following url pattern for logging in urls.py: from django.contrib import admin from django.urls import ...
12 votes
2 answers
22k views

How to programmably create an User in Django?

I have 3 apps in one project. App1 : use from enduser(web view based app) App2 : use from service provider(web service) App3 : use from system administrator. I want to use django authentication ...
0 votes
1 answer
109 views

UserModel.objects,get(email=email) returns none

I am trying to write a custom UserModel and Email Authentication backend. When I tried to override authenticate method. user=UserModel.objects.get(email=email) returned none. Here are my models.py , ...
1 vote
1 answer
53 views

CreateView creates user but doesn't log user in

I am trying to make a class-based registration view equivalent of my old function based registration view. When I register as a new user, a user is created but is not logged in after registration, and ...
0 votes
0 answers
43 views

How to use 'auth_user' table of remote database in django?

I want to access 'auth_user' table from another Django project and use it in my current Django project. I am using database routers:- DATABASE_ROUTERS = ['to.your.router.CurrentRouter'] DATABASES = { ...
4 votes
3 answers
10k views

No module named 'backends'

I was doing this simple django tutorial http://www.madewithtea.com/simple-todo-api-with-django-and-oauth2.html This is my settings.py file import os BASE_DIR = os.path.dirname(os.path.dirname(os....
1 vote
0 answers
773 views

What is the correct way to implement Django password history?

I have implemented a solution for checking a new password against the last 5 passwords like so: Created 5 fields in a user profile table to store the encrypted passwords On creating a new user, I ...
0 votes
1 answer
95 views

Django authenticationform and active users

If I change a current user's status to inactive, they are not able to login. This is expected. However, the error message they receive is to enter in a proper username and password. I expect that they ...
-1 votes
1 answer
35 views

What are u use in project with django.contrib.auth.models user

I wanna ask what u do when wanna create more than just name passwod and password_confirm . Like "from django.contrib.auth.models import Abstractuser class name model(Abstractuser):" and add ...
0 votes
0 answers
30 views

Create Cart object once user logs in

My app is built so that only authenticated users can purchase items so there is only need for a cart when the use logs in, my script then pulls the cart id that relates to that user so my API can ...

1 2
3
4 5
39