Django管理页面缺少IIS中的CSS [英] Django Admin Page missing CSS in IIS
问题描述
我收到与此
我正在使用Django 1.8.4和Python 3.4.
这是我当前的配置:
settings.py
#像这样在项目内部构建路径:os.path.join(BASE_DIR,...)导入操作系统BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__)))#快速启动开发设置-不适合生产#参见https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/#安全警告:对生产中使用的秘密密钥保密!SECRET_KEY ='& y%= 6k2y4z5_ut3z#& 1l2lh3v12#zyxws)o& 5 ^ fj ^ ik ^ 79pys('#安全警告:不要在生产中打开调试的情况下运行!调试=正确ALLOWED_HOSTS = []#应用定义INSTALLED_APPS =('django.contrib.admin',#admin网站'django.contrib.auth',#身份验证系统'django.contrib.contenttypes',内容类型的#framework'django.contrib.sessions',#ssession框架'django.contrib.messages',#消息框架'django.contrib.staticfiles',#framework用于管理静态文件民意调查",)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'模板= [{'BACKEND':'django.template.backends.django.DjangoTemplates','DIRS':[],'APP_DIRS':是的,'选项': {'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'#数据库#https://docs.djangoproject.com/zh-CN/1.8/ref/settings/#databases数据库= {'默认': {'ENGINE':'django.db.backends.sqlite3','名称':os.path.join(BASE_DIR,'db.sqlite3'),}}#国际化#https://docs.djangoproject.com/en/1.8/topics/i18n/LANGUAGE_CODE ='en-us'TIME_ZONE ='UTC'USE_I18N =真USE_L10N =真USE_TZ =真#静态文件(CSS,JavaScript,图像)#https://docs.djangoproject.com/zh/1.8/howto/static-files/STATIC_URL ='/静态/'
urls.py
从django.conf.urls中的 导入包括URL从django.contrib导入管理员urlpatterns = [url(r'^ admin/',include(admin.site.urls)),]
wsgi.py
import os从django.core.wsgi导入get_wsgi_applicationos.environ.setdefault("DJANGO_SETTINGS_MODULE","FirstSite.settings")应用程序= get_wsgi_application()
manage.py
import os导入系统如果__name__ =="__main__":os.environ.setdefault("DJANGO_SETTINGS_MODULE","FirstSite.settings")从django.core.management导入execute_from_command_lineexecute_from_command_line(sys.argv)
在同事的帮助下,我找到了答案.
答案在此处突出显示:链接
如果您遵循上述解决方案,请记住以下几点(上述人员提到的内容):
- 保存所有CSS,jpegs等文件的静态文件夹与解决方案中引用的静态文件夹不同
- 确保您运行命令collectstatic将所有静态文件从STATIC_URL文件夹编译到STATIC_ROOT文件夹
- 当您运行collectstatic时,它也会同时编译Admin静态文件
I am getting a similar error to this post, but it only happens when I go to the website I set up in IIS 2012R2.
I am following this tutorial to start a web app, and I used this video to set up Django with IIS. I successfully set up the Django using IIS, but I a missing the CSS on the admin page.
Note that the admin page displays the CSS items if I run the page using runserver command.
python manage.py runserver
But if I run it through http://127.0.0.1:8003/admin/ in IE (setup through IIS), I get the picture shown below. I tried this in Chrome, and it gave me same results.
Do I need configure my wfastcgi.py file to show CSS? In the video tutorial, the author talks about a static folder in IIS for JPEGS, Javascript...do I need to configure this?
I am using Django 1.8.4 and Python 3.4.
This is my current configuration:
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)
I was able to find an answer with the help of a colleague.
The answer is highlighted here: Link
If you follow the above solution, please keep in mind the following (which is what the above person mentioned):
- The Static folder where you keep all the CSS, jpegs, etc files is not the same as the static folder they are referring to in the solution
- Make sure you run the command collectstatic to compile all the static files from the STATIC_URL folder to the STATIC_ROOT folder
- When you run the collectstatic it will compile the Admin static files as well
这篇关于Django管理页面缺少IIS中的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!