无法使用正确的用户名和密码登录Django admin(Can't login to Django admin using correct username and password)

编程入门 行业动态 更新时间:2024-10-15 12:37:27
无法使用正确的用户名和密码登录Django admin(Can't login to Django admin using correct username and password)

我使用ngnix , gunicorn和Postgresql数据库在DigitalOcean上部署了一个Django应用程序。 一切正常,当我运行python manage.py syncdb ,我能够创建一个很好地填充我的数据库的用户。

我遇到的问题是,当我尝试登录Django管理界面时,系统会提示我使用了错误的用户名和/或密码。 我很确定凭据是正确的,因为我已经尝试多次设置数据库。

任何想法为什么Django认为我输入错误的用户信息?

谢谢!

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! SECRET_KEY = 'XXXXXXXXXXXXXXX' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'qvido.urls' WSGI_APPLICATION = 'qvido.wsgi.application' # Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydbname', 'USER': 'user', 'PASSWORD': 'pass!', 'HOST': 'localhost', 'ROOT': '', } } # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_ROOT = '/webapps/django-env/static/' STATIC_URL = '/static/'

WSGI.py看起来像

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qvido.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()

编辑

好吧,我也试过做python manage.py dbshell和select * from auth_user; 我看到我创建的用户但仍然无法使用它登录。 这么奇怪。

I have deployed a Django application on DigitalOcean using ngnix, gunicorn and a Postgresql database. Everything works just fine and when I run python manage.py syncdb and I'm able to create a user which populates my DB nicely.

Problem I'm having is that when I try to login to the Django admin interface I get prompted that I'm using the wrong username and/or password. I'm pretty sure the credentials are right as I have tried setting up the db multiple times.

Any ideas why Django thinks I'm inputing the wrong user info?

Thanks!

SETTINGS.py looks like

# 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! SECRET_KEY = 'XXXXXXXXXXXXXXX' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'qvido.urls' WSGI_APPLICATION = 'qvido.wsgi.application' # Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydbname', 'USER': 'user', 'PASSWORD': 'pass!', 'HOST': 'localhost', 'ROOT': '', } } # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_ROOT = '/webapps/django-env/static/' STATIC_URL = '/static/'

WSGI.py looks like

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qvido.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()

EDIT

Ok, I aslo tried doing python manage.py dbshell and the select * from auth_user; I see the user I've created but still can't log in with it. So strange.

最满意答案

我为迟到的答案道歉,但我相信这可能对某人有用。

我遇到了同样的问题。 在阅读了原始问题的所有评论之后,我能够弄清楚发生了什么。

在开发过程中,我将数据库从旧的测试数据库切换到新的测试数据库,其中包括所有必需的表,而不仅仅是更改现有的数据库。 我只更改了settings.py文件以更新新数据库的位置,并且没有触及wsgi.py文件。 迁移到新数据库并从项目中删除旧文件后,我的管理员用户在新数据库中不存在。

基于@Torsten Engelbrecht和OP的评论,我需要做的就是运行@Alen thomas建议的命令,使其再次起作用:

python manage.py createsuperuser

此时我可以设置我之前使用的相同管理员帐户,因为它已不存在。 现在一切正常。 这可能看起来有点傻,但检查一下是值得的

So, I found the answer to why this was happening and indeed @scriptmonster was correct.

When I installed Django, Gunicorn etc. in my virtual-env I used sudo pip install which installed these outside of my virtaul-env.

I ran sudo chown -R myuser:myuser /webapps/myenv and then ran pip install django and pip install gunicorn again and everything worked just fine.

更多推荐

本文发布于:2023-08-06 07:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户名   正确   密码   Django   admin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!