在 django 站点中使用两个设置(prod 和 dev),dev 不允许管理员

湖人队

目前我正在使用两个单独的设置。其中之一是我在每次推送(postgres)时上传到 heroku 的 prod 设置文件。我用于开发的另一个(sqlite3)。一切都在生产中运行良好(谢天谢地)但是,管理站点在生产中不起作用。

python manage.py --settings=djangoroot.devsettings用来运行开发服务器。但是,管理站点给了我以下内容:

DoesNotExist at /admin/login/
Site matching query does not exist.

这是我的 devsettings.py:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'c(s+3-(=_22lr86m)6km!kn&q9irg7fn$19=--wl*p=)k_bgl&'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['djangoandreact.herokuapp.com', '127.0.0.1']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'corsheaders',
    'rest_auth',
    'rest_auth.registration',
    'rest_framework',
    'rest_framework.authtoken',

    'articles'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
]

ROOT_URLCONF = 'djangoroot.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'build')],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'djangoroot.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

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/2.0/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/2.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'build/static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # 'rest_framework.permissions.AllowAny'
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    )
}

CORS_ORIGIN_ALLOW_ALL = True

ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_VERIFICATION = 'none'
JPG

由于您'django.contrib.sites'在您的中使用INSTALLED_APPS,您应该SITE_ID=1在您的devsettings

参考中设置/添加
1.站点匹配查询不存在

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

不允许在WordPress中使用网络管理员普通用户管理员面板

如何为django和apache设置dev和prod的wsgi.py

不允许使用Django + Angular方法PUT和POST

Django:如果未以管理员身份登录,则不允许用户查看视图/模板

我可以在Django App的DEV,STAGE和PROD环境中使用单个Azure AD B2C租户吗?

Django模型和Django管理员

如何使用Symfony环境dev和prod

Linux如何使用/ dev / tty和/ dev / tty0

仅允许在Django模型和管理员中填充一个字段或另一个字段

在Cloudformation中使用Qa,Dev和Prod作为环境

Django多对多和管理员

Django 管理员和模型

在Django管理员中使用Django站点框架

Django如何允许从管理员和来宾语言选择器进行翻译

如何使用Node.js管理Heroku上的DEV和PROD部署

反应本机DEV和PROD变量

Dockerfile和dev / test / prod环境

在管理员中上传图片时,出现错误:不允许使用文件扩展名“ jpg”。允许的扩展名是:”

在两个不同的存储库中管理Azure DEVOPS Git DEV和发布分支是个好主意吗?

在Google Cloud Platform上不允许使用Django,Kubernetes和负载均衡器的主机

使用Redux Dev Tools扩展和Typescript

当以管理员身份运行并添加了策略时,不允许使用'fs-extra'符号链接,自己运行mklink可以吗?

如何在 AWS Lambda 上设置 PROD 和 DEV 环境

错误:带有 ReactJS 和 Django 的 webpack-dev-server

无法使用正确的用户名和密码登录Django管理员

如何允许django管理员将字段设置为NULL?

Django管理员取消注册站点

Drupal +网站管理员工具:“此位置的站点地图不允许使用此URL。”

不允许使用Django方法(POST)