Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django管理页面中没有css_Python_Css_Django - Fatal编程技术网

Python django管理页面中没有css

Python django管理页面中没有css,python,css,django,Python,Css,Django,我刚刚安装了django 1.7,最近创建了新的项目和应用程序。我已经创建了一个新的超级用户。当我尝试登录到我的超级用户帐户时,django管理页面会出现,但没有css。我不知道我做错了什么。有人能帮我吗 这是我的setting.py: """ Django settings for blog project. For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/setting

我刚刚安装了django 1.7,最近创建了新的项目和应用程序。我已经创建了一个新的超级用户。当我尝试登录到我的超级用户帐户时,django管理页面会出现,但没有css。我不知道我做错了什么。有人能帮我吗

这是我的setting.py:

 """
Django settings for blog project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%j$#fj6ddv$nkgv=v4kez6yi56&z$qffzr%gyz6b!ds-!5xi%e'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'post',
)

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',
)

ROOT_URLCONF = 'blog.urls'

WSGI_APPLICATION = 'blog.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/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.7/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.7/howto/static-files/

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

您应该在settings.py中添加以下内容

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'C:/ProjectPath/static',
]
如果只有1个settings.py文件,则应使用

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
在django 1.8及更高版本中,您还应该定义一个类似“static”的“templates”文件夹。 将html文件放入“templates”文件夹,并在模板(html文件)中添加css/js文件,如“static/css/bootstrap.css”


您的URL.py是否指向静态?无关提示:如果您正在启动项目,请升级到Django 1.8,因为它的LTS(长期支持)OP正在使用Django 1.7<代码>模板是在Django 1.8中引入的。是的,我用Django 1.9中的解决方案解决了相同的问题。您的解决方案是针对Django OP没有的版本。你应该为他的版本编辑它,或者至少建议他升级
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.dirname(__file__), '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',
        ],
    },
},
]