Python Django 在脚本和图像上返回 400 条 GET 消息
Posted
技术标签:
【中文标题】Python Django 在脚本和图像上返回 400 条 GET 消息【英文标题】:Python Django returning 400 GET messages on script and images 【发布时间】:2018-01-20 21:00:39 【问题描述】:我有一个 python 服务器正在运行。并且在开始时,它运行应用程序完美地加载图像和脚本。如果我让它运行 24 小时,我发现它会给出 GET 400 错误消息,表示未加载图像/脚本。
我还观察到,如果我用备份完全替换所有应用程序,那么它可能会再次开始完美运行。
我的设置.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/1.9/howto/deployment/checklist/
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'uploads.core',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'uploads.urls'
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'uploads/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',
'django.template.context_processors.media',
],
,
,
]
WSGI_APPLICATION = 'uploads.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'),
# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/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.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
【问题讨论】:
您的问题无法回答。您用来启动“服务器”的命令是什么? 旁注:将生产中使用的密钥保密! @PaulCollingwood python manage.py runserver 0.0.0.0.8000 @MosesKoledoye 我删除了它。谢谢。 serverfault.com/questions/717568/… 【参考方案1】:我终于得到了正确的答案: how to point correctly to static image in django
感谢@4dgaurav
【讨论】:
以上是关于Python Django 在脚本和图像上返回 400 条 GET 消息的主要内容,如果未能解决你的问题,请参考以下文章
如何不在 Python、Django 中生成两次相同的动态图像?