python内置服务器不加载css [英] python built in server not loading css
问题描述
当我runserver django管理员缺少css。Web控制台说,样式表没有加载,因为它的MIME类型application / x-css不是text / css。
这是我的settings.py文件
mysite项目的Django设置。
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS =(
#('Your Name','your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default':{
'ENGINE':'django.db.backends.sqlite3' ,
'NAME':'C:/djangorevision/mysite/sqlite3.db',数据库
'USER':'',#不与sqlite3一起使用。
'PASSWORD':'',#不与sqlite3一起使用。
'HOST':'',
'PORT':'',
}
}
ALLOWED_HOSTS = []
TIME_ZONE ='美国/芝加哥'
LANGUAGE_CODE ='en-us'
SITE_ID = 1
#如果将此设置为False,Django将进行一些优化,以便
#加载国际化机器。
USE_I18N = True
#如果将其设置为False,Django将不会根据当前语言环境格式设置日期,数字和
#日历。
USE_L10N = True
USE_TZ = True
MEDIA_ROOT =''
MEDIA_URL =''
STATIC_ROOT ='C:/ djangorevision / mysite / static'
#静态文件的URL前缀。
#示例:http://media.lawrence.com/static/
STATIC_URL ='/ static /'
#静态文件的附加位置
STATICFILES_DIRS =(
)
#了解如何在
#各个位置找到静态文件的查找器类列表。
STATICFILES_FINDERS =(
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles .finders.DefaultStorageFinder',
)
#使其独一无二,不要与任何人共享。
SECRET_KEY ='* 4#u_xz- + 7cp-x-)w(o * sr1& amp; 1 $ ^ fa409_d @ 7!& amp; z%_(93u = @ s = o'
TEMPLATE_LOADERS =(
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#'django.template .loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES =(
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware .SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware'
#取消注释下一行的简单点击保护:
#'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF ='mysite.urls'
#Django的runserver使用的WSGI应用程序的Python路径
WSGI_APPLICATION ='mysite.wsgi.application'
TEMPLATE_DIRS =(
)
INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib.contenttypes' ,
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#取消注释下一行以启用admin:
'django.contrib.admin',
#取消注释下一行以启用管理员文档:
#'django.contrib.admindocs ',
'polls'
)
pre>
LOGGING = {
'version':1,
'disable_existing_loggers':False,
'filters':{
' require_debug_false':{
}
},
'处理程序':{
'mail_admins':{
'level':'ERROR',
'过滤器':['require_debug_false'],
'class':'django.utils.log.AdminEma ilHandler'
}
},
'loggers':{
'django.request':{
'handlers':['mail_admins'],
'level':'ERROR',
'propagate':True,`enter code here`
},
}
}
我刚遇到同样的问题。而且似乎你对Dreamweaver是对的。将上述字符串添加到settings.py中并没有帮助我。
我已经运行搜索 .css
regedit并更改了大多数可疑的注册表项/记录,其中
- 可能与将.css文件作为应用程序/ x-css类型
- 可能会将.css文件扩展名与应用程序关联,特别是Dreamweaver。
我两次迭代,我不能确定哪一个是正确的镜头,因为它可能需要一些时间来更新某些缓存等。
虽然我改变了两个位置:
- HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.css
- HKEY_CLASSES_ROOT\。 css
我重命名(通过添加前导 - ,以便在必要时可以恢复)与 .css
与所有应用程序(包括Dreamweaver,记事本等)和sta文件关联ting .css
文件作为应用程序/ x-css类型。
之后,问题已解决,Django CSS样式按照预期的方式正确应用。
when i runserver the django admin is missing css.The web console says that style sheet was not loaded because its MIME type,"application/x-css", is not "text/css". This is my settings.py file
Django settings for mysite project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/djangorevision/mysite/sqlite3.db', database
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '',
'PORT': '',
}
}
ALLOWED_HOSTS = []
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = 'C:/djangorevision/mysite/static'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '*4#u_xz-+7cp-x-)w(o*sr1&1$^fa409_d@7!&z%_(93u=@s=o'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'
TEMPLATE_DIRS = (
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'polls'
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,`enter code here`
},
}
}
I just ran into the same problem. And it seems you are right about Dreamweaver. Adding above mentioned strings into settings.py didn't helped me.
I have run search for .css
at regedit and changed most suspicious registry keys/records which
- could be related to treating .css files as application/x-css type
- could be related to associating .css file extension to opening with applications, especially Dreamweaver.
It took me two iterations and I can not say for sure which one was the right shot as it might needed some time to update some cache, etc.
Though I changed it at two locations:
- HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.css
- HKEY_CLASSES_ROOT\.css
I renamed (by adding leading '--' so that it could be recovered if necessary) keys/records related to .css
files association with all applications (including Dreamweaver, Notepad, etc.) and stating .css
files as application/x-css type.
After that the issue was resolved and Django CSS styles were correctly applied as it was expected.
这篇关于python内置服务器不加载css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!