I have just install django 1.7 and recently create new project and application. I have create a new superuser. when I try to login to my superuser account the django administration page appear without css. I do not what's wrong i did. can anyone help me?
我刚刚安装了django 1.7,最近创建了新的项目和应用程序。我创建了一个新的超级用户。当我尝试登录到我的超级用户帐户时,django管理页面显示为没有css的。我不知道我做错了什么。谁能帮我吗?
Here is my setting.py:
这是我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')
1 个解决方案
#1
1
You should add following to your settings.py
您应该在您的set .py中添加以下内容
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'C:/ProjectPath/static',
]
If you have only 1 settings.py file, you should change BASE_DIR value with
如果你只有一个设置。py文件,应该使用BASE_DIR值进行更改
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
In django 1.8 and later, you should also define a 'templates' folder like 'static'. Put your html files into "templates" folder and add css/js files like "static/css/bootstrap.css" in your templates(html files).
在django 1.8和以后的版本中,还应该定义一个“模板”文件夹,比如“static”。将html文件放入“template”文件夹中,并添加css/js文件,如“static/css/bootstrap”。在你的模板(html文件)中。
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',
],
},
},
]
#1
1
You should add following to your settings.py
您应该在您的set .py中添加以下内容
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'C:/ProjectPath/static',
]
If you have only 1 settings.py file, you should change BASE_DIR value with
如果你只有一个设置。py文件,应该使用BASE_DIR值进行更改
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
In django 1.8 and later, you should also define a 'templates' folder like 'static'. Put your html files into "templates" folder and add css/js files like "static/css/bootstrap.css" in your templates(html files).
在django 1.8和以后的版本中,还应该定义一个“模板”文件夹,比如“static”。将html文件放入“template”文件夹中,并添加css/js文件,如“static/css/bootstrap”。在你的模板(html文件)中。
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',
],
},
},
]