我的生产模式遇到一些问题。在这种情况下,成功登录后,我在管理中的登录页面不会重定向到管理页面。我得到的服务器响应为:200。
[pid: 58|app: 0|req: 2/3] 172.17.0.1 () {46 个变量,976 字节} [Wed Jun 22 14:07:32 2022] POST /admin/login/?next=/ admin/ => 在 40 毫秒内生成 2425 字节 (HTTP/1.0 200) 623 字节中的 12 个标头(1 个开关在核心 0 上)
但是,它保留在相同的登录页面中。并且,还显示一条消息:“请输入员工帐户的正确电子邮件地址和密码。请注意,这两个字段都可能区分大小写。”
嗯...已经尝试了解我的超级用户是否不是使用哈希密码创建的。但它是。我做了一个“python manage.py changepassword”来确定。
我没有任何线索来解决这个问题。
谨告知,我正在使用 UWSGI 和 NGINX。
设置.py
"""
Django §ettings for myophio project.
Generated by 'django-admin startproject' using Django 4.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
from pathlib import Path
from datetime import timedelta
from django.conf import settings
from django.utils.text import slugify
import environ
env = environ.Env(
DEBUG = (bool,False)
)
try:
from ..logger_settings import *
except Exception as e:
# in case of any error, pass silently.
pass
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
# False if not in os.environ because of casting above
DEBUG = env('DEBUG')
ROOT_URLCONF = 'myophio.urls'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
LOGIN_URL = "/auth/login/"
LOGOUT_REDIRECT_URL = "/auth/login/"
GROUPS_MANAGER = {
'AUTH_MODELS_SYNC': True,
}
GROUPS_MANAGER = {
# ... other settings
'SLUGIFY_FUNCTION': lambda s: slugify(s, to_lower=True),
'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s, to_lower=True, separator="_")
}
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'groups_manager',
'guardian',
'django_countries',
'jsignature',
'corsheaders',
'rest_framework',
'rest_framework.authtoken',
'api',
'distrib_api',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
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',
],
},
},
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.AllowAny',
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
],
'DEFAULT_AUTHENTICATION_CLASSES': [ # new
'rest_framework.authentication.TokenAuthentication', # new
'rest_framework.authentication.SessionAuthentication', # new
],
}
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
# Password validation
# https://docs.djangoproject.com/en/4.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/4.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/4.0/howto/static-files/
STATIC_URL = 'staticfiles/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/UploadedFiles/')
MEDIA_URL = 'media/UploadedFiles/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTH_USER_MODEL = 'api.CustomUser'
AUTHENTICATION_BACKENDS = ['api.backends.EmailBackend']
在生产环境中,确保将 settings.py 中的调试模式设置为 FALSE 和 ALLOWED_HOST =["*"] 首先写这个命令: sudo systemctl 重新加载 nginx.service 如果这不起作用,那么写这个 须藤重新启动 这次运行之后 systemctl 状态 nginx.service 这应该可以完成工作