这是一个奇怪的问题,但是我不能使用Heroku部署的Django应用程序登录到我的管理界面。每当我输入正确的凭据时,我都会收到一个错误,声明Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.我可以在shell中进行本地身份验证,当我运行简单的本地django服务器时,但在heroku部署的版本上不能。你知道为什么吗?这是我的settings.py文件。它是使用Heroku配置的模板自动生成的,并使用以下命令$ django-admin startproject --template=https://github.com/heroku/heroku-django-template/archive/master.zip --name=Procfile myproject运行
settings.py
import os
import dj_database_url
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'pepfolio.urls'
TEMPLATES = (
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': DEBUG,
},
},
)
WSGI_APPLICATION = 'pepfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
AUTH_PASSWORD_VALIDATORS = (
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
)
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
# 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 files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'发布于 2020-04-10 21:30:58
我也遇到过类似的问题。然后我通过运行以下命令创建了一个超级用户:
$ heroku run python manage.py createsuperuser然后:
$ git push -f heroku master
$ heroku run python manage.py migrate它工作得很好。
发布于 2021-02-24 04:46:02
这对我很有效:
heroku run python manage.py createsuperuser -a <app_name>
创建超级用户后,刷新您的应用程序&确保在用户名部分使用第一个大写字母,如"raj“而不是"Raj”。
编辑:-在前面添加了-a标志,如果没有这个标志,heroku将抛出错误
发布于 2017-05-26 23:49:37
我遇到了类似的错误,但是我注意到你的settings.py中有一些我觉得应该改变的东西,当你迁移到heroku时,默认数据库需要像这样更改为postgresql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}}
您可以在Heroku应用程序的资源标签->add-ons->postgresql->view credentials中找到这些凭据。
有关详细信息,请参阅以下链接:
https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-DATABASES
此链接告诉您如何将local_settings与设置分开:https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/heroku/
希望这能有所帮助!
https://stackoverflow.com/questions/36938414
复制相似问题