72👍
Steps to debug:
- Make sure that your Database is synced
- Double check that you have a django_session table
- Try to authenticate
- Do you see a record being created in the
django_session
table?
- Do you see a record being created in the
IF NOT
- remove non-standard settings
- AUTHENTICATION_BACKENDS = (‘django.contrib.auth.backends.ModelBackend’,)
- SESSION_EXPIRE_AT_BROWSER_CLOSE = True
- SESSION_SAVE_EVERY_REQUEST = True
- SESSION_COOKIE_AGE = 86400 # sec
- SESSION_COOKIE_DOMAIN = None
- SESSION_COOKIE_NAME = ‘DSESSIONID’
- SESSION_COOKIE_SECURE = False
- Make sure that your Database is synced
- Double check that you have a
django_session
table
- Double check that you have a
- Try to authenticate
- Do you see a record being created in the
django_session
table?
- Do you see a record being created in the
Let me know if this turns up any useful debug.
Sample settings file: https://github.com/fyaconiello/Django-Blank-Bare-Bones-CMS/blob/master/dbbbcms/settings.py
22👍
>>> from django.contrib.auth import authenticate
>>> u = authenticate(username="user", password="pass")
>>> u.is_staff = True
>>> u.is_superuser = True
Is there something else I'm missing?
u.is_active
should be True
- [Django]-Django 1.7 migrate gets error "table already exists"
- [Django]-Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
- [Django]-Mac OS X – EnvironmentError: mysql_config not found
14👍
I had this problem. The issue is that in production I set two variables to True
that allowed me to connect to the site using https.
SESSION_COOKIE_SECURE
and CSRF_COOKIE_SECURE
should be set to False
if you are developing on localhost http. Changing these two variables to False
allowed me to sign into the admin site when developing locally.
- [Django]-Getting a count of objects in a queryset in Django
- [Django]-Django REST Framework : "This field is required." with required=False and unique_together
- [Django]-Get the latest record with filter in Django
4👍
After not being able to log in myself, I saw in the comment above someone mentioned about removing non-standard settings.
Adding this to my local settings solved it for me
SESSION_COOKIE_SECURE = False
- [Django]-Django: TemplateDoesNotExist (rest_framework/api.html)
- [Django]-Django select_for_update cannot be used outside of a transaction
- [Django]-Django ModelForm: What is save(commit=False) used for?
3👍
I don’t believe the admin password is stored in the settings.py file. It’s created when you first syncdb. I am thinking you either skipped creating the superuser or just made a typo.
Try running in terminal at your projects root.:
python django-admin.py createsuperuser
That will allow you to retype your admin login. Also seen here https://docs.djangoproject.com/en/dev/ref/django-admin/
- [Django]-Annotating a Sum results in None rather than zero
- [Django]-Django 2 – How to register a user using email confirmation and CBVs?
- [Django]-Tying in to Django Admin's Model History
3👍
Did you try by creating the user with :
python manage.py createsuperuser
I have the same issue when I create the db on a test machine and migrate it to the deployment server…
- [Django]-How do I import the Django DoesNotExist exception?
- [Django]-Django urlsafe base64 decoding with decryption
- [Django]-Creating a JSON response using Django and Python
3👍
We had a similar issue in our app and these might help:
-
Use cleanup command to clear older sessions from django_sessions
-
Check the cookie size in firefox(firebug) or chrome developer tools. Because messaging is enabled by default in admin(django.contrib.messages.middleware.MessageMiddleware), the cookie size sometimes get larger than 4096 bytes with multiple edits and deletes. One quick test is to delete the “message” cookie and see if you can login after that.
And we actually ended up switching to nginx/uwsgi route because of this and other memory related issues with apache. Haven’t seen this repeated in nginx since.
- [Django]-H14 error in heroku – "no web processes running"
- [Django]-How to spread django unit tests over multiple files?
- [Django]-How do I get Django Admin to delete files when I remove an object from the database/model?
2👍
sounds like a session problem because after the post you get redirected and immediately the system has forgotten that you logged in.
try the following:
- check your session backend is working.
- swap it with cache backend if you use db cache backend to check if transaction middleware is messing around.
- try db backend and check if there are sessions stored in the db table
- [Django]-Unittest Django: Mock external API, what is proper way?
- [Django]-Django equivalent of SQL not in
- [Django]-Django – No such table: main.auth_user__old
2👍
This is not OP’s issue, but I am posting this answer in the hopes someone may have gone down the same path as I and arrived at this question as a result.
I came back to an old codebase after a year and was denied access to the admin panel despite all of the usual checks passing (user is present, nothing looks incorrect in the database, all debug modes are on, etc). Unfortunately, I had forgotten that the admin sign in page was not at the usual /admin
route, but rather at an alternate route. The /admin
page was a fake sign in page that always resulted in a failed sign in.
This setup was created using the app django-admin-honeypot
.
- [Django]-Django admin default filter
- [Django]-Can I call a view from within another view?
- [Django]-Django or Django Rest Framework
1👍
I’m not exactly sure, but the problem might be with your URL configuration, concretely in these two lines:
(r'^admin/', include(admin.site.urls)),
(r'^sites/', include("myproject.sites.urls")),
A longer time ago, I had trouble with browsing the admin of my Django project because a single URL configuration overwrote a part of the admin url. It seems that Django doesn’t like it when you specify a custom URL configuration that contains elements which are also part of the admin URL. In your case, you have the app django.contrib.sites
enabled in your settings.py
. You can access the admin panel of this app by going to http://127.0.0.1:8000/admin/sites/
. It might be that your URL configuration with r'^sites/'
in it overrides a part of the admin url. Try renaming this specific URL configuration or disable django.contrib.sites
in INSTALLED_APPS
for testing purposes.
Please note that this is just an assumption. All I know is that Django’s admin panel is a bit picky about URL configurations using similar names like its own URLs. I cannot test it myself at the moment. But maybe this helps you a bit.
- [Django]-Chained method calls indentation style in Python
- [Django]-Filtering dropdown values in django admin
- [Django]-Django DB Settings 'Improperly Configured' Error
1👍
Checking some other articles on this topic, it could be related to sys.path. Can you check and compare sys.path when running the dev server and when running WSGI.
For some details, have a look this and that article. But I would check the sys.path first, before going into the details of this article.
- [Django]-Return the current user with Django Rest Framework
- [Django]-Visual Studio Code: Intellisense not working
- [Django]-Django test app error – Got an error creating the test database: permission denied to create database
1👍
Check that you have at least one site
to work with.
>>> from django.contrib.sites.models import Site
>>> Site.objects.count()
(0.048) SELECT COUNT(*) FROM `django_site`; args=()
1
If you see 0 here – create one.
- [Django]-Django: Model Form "object has no attribute 'cleaned_data'"
- [Django]-What is the best location to put templates in django project?
- [Django]-Switching to PostgreSQL fails loading datadump
1👍
Make sure your database user table having following entry is true:
is_staff => True (if exit).
is_active => True .
is_superuser => True.
- [Django]-What is the equivalent of "none" in django templates?
- [Django]-How to completely dump the data for Django-CMS
- [Django]-Simple guestbook django: __init__() takes 1 positional argument but 2 were given
1👍
For me below settings worked on localhost
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
SESSION_COOKIE_DOMAIN = None
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
- [Django]-Assign variables to child template in {% include %} tag Django
- [Django]-Copy a database column into another in Django
- [Django]-Uwsgi installation error in windows 7
0👍
Disclaimer: I cannot add comments yet, so I have to ask clarification here proposing a solution at the same time. Sorry for that.
Is the user logged-out immediately after logging-in? something like this issue
You can check it in many ways, I suggest to add a hook to the logout signal (you can put it in your models.py):
from django.contrib.auth.signals import user_logged_out
def alertme(sender, user, request, **kwargs):
print ("USER LOGGED OUT!") #or more sophisticate logging
user_logged_out.connect(alertme)
then try to log in and check if the message appears in your console. If it appears, then you have to check if you have a redirect or a customized template calling logout after login. Hope it helps you find the issue.
- [Django]-Django/DRF – 405 Method not allowed on DELETE operation
- [Django]-Whats the difference between using {{STATIC_URL}} and {% static %}
- [Django]-What is the best location to put templates in django project?
0👍
I had same problem and it was just solved after restarting server :
systemctl restart nginx
- [Django]-Django set field value after a form is initialized
- [Django]-Writing a __init__ function to be used in django model
- [Django]-Sort order of Django Admin records
0👍
You can ensure, the created user has been flagged as Is_staff = True, I sometimes forget to flag this to allow users to login to django admin
- [Django]-Django Rest Framework File Upload
- [Django]-Define css class in django Forms
- [Django]-How to change empty_label for modelForm choice field?
0👍
I had a related issue where I’d try to log in and the page would hang before the socket would eventually be killed. It turned out that I was indeed being logged in, but one of the login signal processors was freezing.
Celery couldn’t pass its asynchronous tasks to RabbitMQ because the RabbitMQ server wasn’t able to start.
- [Django]-What is the max size of 'max_length' in Django?
- [Django]-How to access array elements in a Django template?
- [Django]-Sending an SMS to a Cellphone using Django
0👍
For me, I could not login to the admin page in firefox but could login in chrome.
The problem was that I had CSRF_COOKIE_PATH set in my settings.py.
Never use that. It does not not work properly on django 1.8.
- [Django]-Django ManyToMany filter()
- [Django]-How to convert a Django QuerySet to a list?
- [Django]-Django: Get model from string?
0👍
What I did was to navigate manually to the url I wanted to visit.
So like: http://wildlifeapi.herokuapp.com/admin/
was returning the awful Heroku application error.
So what I did was to visit http://wildlifeapi.herokuapp.com/admin/api/animal/
and BINGO! it worked.
The funny thing is that it works well on my phone. It’s probably a django redirection bug.
- [Django]-Django multiple template inheritance – is this the right style?
- [Django]-What's the best way to store a phone number in Django models?
- [Django]-Django: How do I add arbitrary html attributes to input fields on a form?
0👍
My issue was that My Admin Page was not loading and not working. Here is what I did:
pip uninstall django
pip install django==2.2
For more Detail Check Django Documentation.
- [Django]-Sort order of Django Admin records
- [Django]-Django: Catching Integrity Error and showing a customized message using template
- [Django]-Django set default form values
0👍
For anyone who encountered this problem after upgrading Django, the problem could be that the signature of the authenticate
function has changed at some point. If the signature doesn’t match what’s expected, the backend is just ignored. So make sure your custom authentication backend authenticate
method looks like this:
class EmailUsernameAuthenticationBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
# ...
And NOT like this (without the request
argument):
class EmailUsernameAuthenticationBackend(ModelBackend):
def authenticate(self, username=None, password=None, **kwargs):
- [Django]-Determine variable type within django template
- [Django]-Pycharm error Django is not importable in this environment
- [Django]-Django queries: how to filter objects to exclude id which is in a list?
0👍
A bit late for the party, but to me it was different and surprinsingly simpler: for whatever reason my superuser account was gone so, obviously, the solution was I had to create it again.
I’m 99% sure I had executed migrate
and makemigrations
a few times after having created my superuser, but go figure…
It took me about a whole hour to finally figure it out, however. None of the variables discussed here existed in my settings.py -and still don’t to the present moment- (probably because it has been nearly 10 years, so things might have changed considerably), like SESSION_ENGINE
, SESSION_COOKIE_DOMAIN
, CACHE_BACKEND
, django_session
table…
Also, Django’s FAQ on this subject mentions checking if my account is_active
and is_staff
, but unfortunately without ever mentioning how to do it.
- [Django]-How can I use the variables from "views.py" in JavasScript, "<script></script>" in a Django template?
- [Django]-How to make Django serve static files with Gunicorn?
- [Django]-How to export virtualenv?
0👍
For my case it is always the issue with SESSION_COOKIE_DOMAIN:
On local machine I set it like:
SESSION_COOKIE_DOMAIN = 'localhost'
On remote one, domain one, like:
SESSION_COOKIE_DOMAIN = 'yourdomainname.com'
- [Django]-Django Sitemaps and "normal" views
- [Django]-Can you give a Django app a verbose name for use throughout the admin?
- [Django]-In Django models.py, what's the difference between default, null, and blank?
0👍
In my case, I was not able to log in because I was using email in the place of username (which in my case was "admin") to try to log in. So do ensure you’re using the right username and password to log in
- [Django]-Sort order of Django Admin records
- [Django]-Cannot access django app through ip address while accessing it through localhost
- [Django]-How do you skip a unit test in Django?
-1👍
Use some other virtual environment.it worked for me when i used conda environment.
- [Django]-Django admin default filter
- [Django]-Getting a count of objects in a queryset in Django
- [Django]-Simple guestbook django: __init__() takes 1 positional argument but 2 were given