标签:nginx django gunicorn django-grappelli
我在Ubuntu服务器上运行django 1.4和grappelli 2.4.3,我在生产时通过Windows网络系统查看.当我使用RDP在Ubuntu机器上查看它时,在开发服务器上一切正常.
settings.py的相关部分是:
STATIC_ROOT = os.path.join(os.path.dirname(__file__), '../03_static_files/collected/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(os.path.dirname(__file__), '../03_static_files/'),
os.path.join(os.path.dirname(__file__), '../03_static_files/admin/'),
os.path.join(os.path.dirname(__file__), '../03_static_files/filebrowser/'),
os.path.join(os.path.dirname(__file__), '../03_static_files/grappelli/'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# apps I added but didn't create
'south',
'grappelli',
'filebrowser',
'tinymce',
'haystack',
'gunicorn',
'debug_toolbar',
'taggit',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
# apps I created
'community',
'fts',
'guidance',
'news',
)
我运行了collectstatic,但管理站点显然只是部分呈现.它肯定会拿起一些CSS,因为有些元素是样式化的.但它并没有吸引其他人,因为它看起来很混乱.我的Nginx或Gunicorn错误日志都没有显示任何404,如果我直接将浏览器指向他们,我可以下载所有的css和js文件.
管理站点目前在IE8和IE9中都是这样的:
该网站的其他一切运行良好. Django调试工具栏说(工作)开发服务器版本和上面的生产版本呈现相同的模板.删除grappelli时,正常的django admin会正常显示.我试过更改我的Nginx配置文件
location /admin/media/ {
root /path/to/django/contrib;
}
至
location /admin/media/ {
root /path/to/grappelli;
}
没有变化.谁能告诉我哪里出错了?
解决方法:
在那里检查静态媒体.
检查所有那些os这些设置…
STATIC_URL = '/static/'
STATIC_ROOT is something like os.path.join(PROJECT_PATH, "static"),
ADMIN_MEDIA_PREFIX = '/static/grappelli/' (or whatever your static directory is)
接下来检查你的
DEBUG = False or True ?
TEMPLATE_DEBUG = DEBUG
如果为false,它将使用nginx提供文件,但不会
另一个例子…
STATIC_URL = '/static/'
STATIC_ROOT = '/home/foo/devel/static'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/foo/devel/media'
# the following is deprecated but is it seems grappelly requires it
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"
STATIC_FILES = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
标签:nginx,django,gunicorn,django-grappelli 来源: https://codeday.me/bug/20190520/1143494.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。