把settings.py中的DEBUG设置为False前端页面显示不正常了
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ['*']
错误信息
但开启后就能正常显示了,这是什么原因引起的?
settings.py代码
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = 'd+eb61(a0&cu&)0dmok#g9kl1&!+*e*jo5v#(t5#do68%ncdow'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'south',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysite',
'USER': 'mysite',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'zh-cn'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
1
Archangel_SDY 2015-04-20 16:53:58 +08:00 3
DEBUG=False 就不会用自带的 server 去 serve js/css 等静态文件了,你需要用 nginx 之类的去做静态文件的 server.
|
2
fxxkgw 2015-04-20 17:00:49 +08:00 1
开启后用的是自带的http服务器,关闭后用的安装的Apache或者nginx之类的,应该是web服务器或者uwsgi之类没设置好吧。
PS: STATIC_ROOT设置为css js这些文件所在的templates目前的上一级。。 |
3
zjgsamuel 2015-04-20 17:02:34 +08:00 1
静态文件 设置 参见1楼~~
|
4
imkh OP |
5
oott123 2015-04-20 19:20:35 +08:00
SECRET_KEY 建议换一下。
|
6
sallowdish 2015-04-21 02:35:17 +08:00
./manage.py collectstatic
|
7
twor2 2015-04-26 23:30:32 +08:00
Windows 下面用 pycharm 开发并运行, 无专门的 http 服务器,是不是debug =false 后,无论如何设定都会样式丢失?
如果想在非调试状态下运行,必须暗转一个 Apache 之类? |
8
bravecarrot 2015-05-06 09:13:06 +08:00 via iPad
@twor2 不布置web容器,就是dev环境,一定要开debug。想换成apache之类的,在关闭debug后,还要collectstatic。参见文档中关于static的部分。也可以去#django irc问问。
|
9
twor2 2015-05-06 13:29:04 +08:00
@bravecarrot 现在搞明白了,前几天花不少时间查找 google 和 测试
|