Django admin asks for login after every click

2024/10/3 17:17:35

I'm working on a Django app hosted on Heroku. I'm able to login to the admin with my username, password. But on every single click (or on each click after a few seconds) it redirects me to the login page again with the ?next=/admin/model added to the url. Infact sometimes it asks for login multiple times before it lets me view the admin console. This behaviour is not reflected in local deployment. Admin works just fine locally.

I tried the suggestion mentioned here:https://docs.djangoproject.com/en/1.8/faq/admin/#i-can-t-log-in-when-i-enter-a-valid-username-and-password-it-just-brings-up-the-login-page-again-with-no-error-messages. But that does not help.

Any clue what I could be doing wrong?

Here is my settings.py:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = TrueTEMPLATE_DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = ('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','haystack','hash','smuggler',)MIDDLEWARE_CLASSES = ('django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','django.middleware.csrf.CsrfViewMiddleware',
)ROOT_URLCONF = 'ssite.urls'WSGI_APPLICATION = 'ssite.wsgi.application'SESSION_ENGINE = "django.contrib.sessions.backends.cache" TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth','django.core.context_processors.debug','django.core.context_processors.i18n','django.core.context_processors.media','django.core.context_processors.static','django.core.context_processors.tz','django.contrib.messages.context_processors.messages','django.contrib.auth.context_processors.auth',AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2','NAME': 'hash','USER': 'dc','PASSWORD': 'dc','HOST': '127.0.0.1','PORT': '5432',}
}LANGUAGE_CODE = 'en-us'TIME_ZONE =  'Asia/Kolkata'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = TrueSESSION_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 = FalseBASE_DIR = os.path.dirname(os.path.abspath(__file__))MEDIA_ROOT = os.path.join(BASE_DIR, 'media')MEDIA_URL = '/media/'HAYSTACK_CONNECTIONS = {'default': {'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine','URL': 'http://127.0.0.1:9200/','INDEX_NAME': 'haystack',},
}# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')# Allow all host headers
ALLOWED_HOSTS = ['*']# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'FIXTURE_DIRS = (os.path.join(BASE_DIR, 'fixtures'),
)from urlparse import urlparsees = urlparse(os.environ.get('SEARCHBOX_URL') or 'http://127.0.0.1:9200/')port = es.port or 80HAYSTACK_CONNECTIONS = {'default': {'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine','URL': es.scheme + '://' + es.hostname + ':' + str(port),'INDEX_NAME': 'documents',},
}if es.username:HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password}try:from local_settings import *
except ImportError as e:pass
Answer

In my case, this happened because I was running another Django development server at the same time (same domain, different port). I don't know the details of what caused this issue, but shutting down the other server fixed the problem.

EDIT
In case you missed the docs linked to in the question: if you need to run multiple django servers, you may be able to resolve this issue by setting a different SESSION_COOKIE_NAME for each.

https://en.xdnf.cn/q/70706.html

Related Q&A

Change numerical Data to Categorical Data - Pandas [duplicate]

This question already has answers here:How to create new values in a pandas dataframe column based on values from another column(2 answers)Closed 6 years ago.I have a pandas dataframe which has a numer…

Why is dataclasses.astuple returning a deepcopy of class attributes?

In the code below the astuple function is carrying out a deep copy of a class attribute of the dataclass. Why is it not producing the same result as the function my_tuple? import copy import dataclass…

customize dateutil.parser century inference logic

I am working on old text files with 2-digit years where the default century logic in dateutil.parser doesnt seem to work well. For example, the attack on Pearl Harbor was not on dparser.parse("12…

How can I check a Python unicode string to see that it *actually* is proper Unicode?

So I have this page:http://hub.iis.sinica.edu.tw/cytoHubba/Apparently its all kinds of messed up, as it gets decoded properly but when I try to save it in postgres I get:DatabaseError: invalid byte seq…

Test assertions for tuples with floats

I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other …

Django: Assigning ForeignKey - Unable to get repr for class

I ask this question here because, in my searches, this error has been generally related to queries rather than ForeignKey assignment.The error I am getting occurs in a method of a model. Here is the co…

Counting day-of-week-hour pairs between two dates

Consider the following list of day-of-week-hour pairs in 24H format:{Mon: [9,23],Thu: [12, 13, 14],Tue: [11, 12, 14],Wed: [11, 12, 13, 14]Fri: [13],Sat: [],Sun: [], }and two time points, e.g.:Start:dat…

Download A Single File Using Multiple Threads

Im trying to create a Download Manager for Linux that lets me download one single file using multiple threads. This is what Im trying to do : Divide the file to be downloaded into different parts by sp…

Merge string tensors in TensorFlow

I work with a lot of dtype="str" data. Ive been trying to build a simple graph as in https://www.tensorflow.org/versions/master/api_docs/python/train.html#SummaryWriter. For a simple operat…

How to reduce memory usage of threaded python code?

I wrote about 50 classes that I use to connect and work with websites using mechanize and threading. They all work concurrently, but they dont depend on each other. So that means 1 class - 1 website - …