我收到与此post类似的错误,但只有在我访问我在IIS 2012R2中设置的网站时才会发生此错误。
我正在关注此tutorial以启动网络应用,我使用此video与IIS一起设置Django。我使用IIS成功设置了Django,但我错过了管理页面上的CSS。
请注意,如果我使用runserver命令运行页面,则admin页面会显示CSS项目。
python manage.py runserver
但如果我在IE中通过http://127.0.0.1:8003/admin/运行它(通过IIS设置),我会得到如下所示的图片。我在Chrome中试过这个,它给了我相同的结果。
我是否需要配置我的wfastcgi.py文件来显示CSS?在视频教程中,作者在IIS中讨论了JPEGS中的静态文件夹,Javascript ......我需要配置它吗?
我正在使用Django 1.8.4和Python 3.4。
这是我目前的配置:
settings.py
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
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.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&y%=6k2y4z5_ut3z#&1l2lh3v12#zyxws)o&5^fj^ik^79pys('
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin', #admin site
'django.contrib.auth', #authentication system
'django.contrib.contenttypes', #framework for content types
'django.contrib.sessions', #ssession framework
'django.contrib.messages', #messaging framework
'django.contrib.staticfiles', #framework for managing static files
'polls',
)
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 = 'FirstSite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'FirstSite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/
STATIC_URL = '/static/'
urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),]
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FirstSite.settings")
application = get_wsgi_application()
manage.py
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FirstSite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
答案 0 :(得分:2)
您应该在settings.py中设置STATICFILES_DIRS设置,以映射到存储CSS,JS和图像的静态文件夹。
STATIC_URL = 'http://www.example.com/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
此外,如果你运行' manage.py collectstatic'你应该定义
STATIC_ROOT = "/path/to/static/destination/folder/"
这是提供静态文件的最佳方式。
STATIC设置参考:Django Documentation
答案 1 :(得分:1)
我能够在同事的帮助下找到答案。
答案在此处突出显示:Link
如果您按照上述解决方案,请记住以下内容(这是上述人员提到的):