django admin css没有加载设置

时间:2017-04-08 06:30:53

标签: python css django admin

当打开Django时,admin的css页面没有loading.it显示没有css的简单页面。

我的setting.py文件设置为:

STATIC_URL = '/static/'
STATIC_ROOT = "C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/myprograms/mysite/mysite/static/"
STATICFILES_DIRS = [
'C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/django/contrib/admin/static/',]

我的项目在

C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/myprograms/mysite

尝试使用

解决
 $ python manage.py collectstatic

但无法解决

在我的机器上安装

Python version :3.6.0
Django version :1.10.6

3 个答案:

答案 0 :(得分:1)

它可能是绝对路径中的某种东西。将其添加到您的settings.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__)))

然后,定义您的STATIC_ROOT

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS执行相同操作。

答案 1 :(得分:1)

您可以在浏览器控制台中检查CSS的路径(如果未加载它,则应该是404 - 找不到文件)。使用该信息,您应该知道路径是否错误(路径指向不存在此类文件的位置)。如果路径错误,请使用@Nifled的设置。

另一个想法是您的TEMPLATES列表错误,请尝试:

ind <- substring(tolower(df$city), 1, 3)
ifelse(ind == 'new', 'New York', ifelse(ind == 'lond', 'London', 'Mumbai'))
 #[1] "New York" "New York" "New York" "New York" "New York" "Mumbai"   "Mumbai"  
 #[8] "Mumbai"   "Mumbai"   "Mumbai"

最后一个想法是你没有在你的virtualenv中安装Django,而是在系统中。激活virtualenv使用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', ], }, }, ] 并查看是否获得结果,如果不是=&gt;你没有在虚拟环境中安装Django。

答案 2 :(得分:0)

我在我的setting.py文件中添加了以下内容,现在它正常工作:

import mimetypes
mimetypes.add_type("text/css", ".css", True)
相关问题