当我的DEBUG = False时显示“错误:-1”,而当我的DEBUG = True时显示“错误:-2”。
我将使用 python 3.7.7 和 django 3.0.4 。
我的settings.py文件是:-
DEBUG = False
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home.apps.HomeConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = '***************'
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',
],
},
},
]
WSGI_APPLICATION = '*************************'
# Database
# https://docs.djangoproject.com/en/3.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/3.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/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
#
#for uploaded image
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#end of uploded image
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
# '/static/',
]
这是“ 错误:1 ”...。[当DEBUG = False时]
[15/Mar/2020 11:14:56] "GET /admin/login/?next=/admin/ HTTP/1.1" 500 4712
[15/Mar/2020 11:14:56] "GET /static/js/jquery-3.2.1.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main2.js HTTP/1.1" 404 21440
[15/Mar/2020 11:14:56] "GET /static/js/bootstrap.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main.js HTTP/1.1" 404 21440
[15/Mar/2020 11:14:56] "GET /static/js/owl.carousel.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /static/js/jquery.marquee.min.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /static/js/main.js HTTP/1.1" 304 0
[15/Mar/2020 11:14:56] "GET /admin/login/js/main.js HTTP/1.1" 404 21440
这是“ 错误:-2 ” ... [当DEBUG = True时]
但是在'DEBUG = True'的时间,我的管理页面已打开,但终端显示以下错误。
[15/Mar/2020 11:15:51] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
每当我尝试在浏览器中打开'/ admin /'时,都会出现错误,但是我的主页[127.0.0.1:8000]可以正常工作。
提前谢谢。
答案 0 :(得分:1)
我们只能从settings.py删除三行
1> django_heroku.settings(locals())
这行是在Heroku上部署Django应用所必需的。
2> STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
3> MIDDLEWARE = [
...
'whitenoise.middleware.WhiteNoiseMiddleware',
]
当DEBUG = False时,第二行和第三行用于在网站上投放静态文件。
消除这三行错误后即可解决, 它将完美运行,没有任何错误。
谢谢您,特别感谢您Alasdair。