【发布时间】:2017-12-27 13:46:53
【问题描述】:
首先,我不知道这只是我的问题还是其他人也有。我的 django admin 的生产版本(我在我的网站中使用它)看起来与我在个人计算机上午餐时看到的不同。
您可以在两张图片中看到差异:
local version (127.0.0.1:8000)
production version(我的网站)
我想说的一点:
我的settings.py:
STATIC_ROOT = '/home/django/django_project/django_project/static'
STATIC_URL = '/static/'
关于路径:
root@myuser:/home/django/django_project/django_project/static# ls
admin css fa fonts img js
运行管理面板时的控制台日志显示与管理面板相关的静态文件(如 jquery.js)无法正确呈现。
mywebsite.com/:12 GET https://mywebsite.com/static/admin/js/vendor/jquery/jquery.js net::ERR_ABORTED
mywebsite.com/:18 GET https://mywebsite.com/static/admin/js/vendor/xregexp/xregexp.js net::ERR_ABORTED
mywebsite.com/:199 GET https://mywebsite.com/static/admin/js/change_form.js net::ERR_ABORTED
mywebsite.com/:208 GET https://mywebsite.com/static/admin/js/prepopulate_init.js net::ERR_ABORTED
mywebsite.com/:12 GET https://mywebsite.com/static/admin/js/vendor/jquery/jquery.js 404 (Not Found)
jquery.init.js:7 Uncaught ReferenceError: jQuery is not defined
at jquery.init.js:7
(anonymous) @ jquery.init.js:7
actions.js:4 Uncaught TypeError: Cannot read property 'fn' of undefined
at actions.js:4
at actions.js:144
(anonymous) @ actions.js:4
(anonymous) @ actions.js:144
prepopulate.js:2 Uncaught TypeError: Cannot read property 'fn' of undefined
at prepopulate.js:2
at prepopulate.js:39
(anonymous) @ prepopulate.js:2
(anonymous) @ prepopulate.js:39
mywebsite.com/:18 GET https://mywebsite.com/static/admin/js/vendor/xregexp/xregexp.js net::ERR_ABORTED
mywebsite.com/:200 GET https://mywebsite.com/static/admin/js/change_form.js net::ERR_ABORTED
mywebsite.com/:209 GET https://mywebsite.com/static/admin/js/prepopulate_init.js 404 (Not Found)
DateTimeShortcuts.js:277 Uncaught TypeError: django.jQuery is not a function
at Object.addCalendar (DateTimeShortcuts.js:277)
at init (DateTimeShortcuts.js:45)
addCalendar @ DateTimeShortcuts.js:277
init @ DateTimeShortcuts.js:45
/missing-admin-media-prefix/img/icon_calendar.gif:1 GET https://mywebsite.com/missing-admin-media-prefix/img/icon_calendar.gif 404 (Not Found)
Image (async)
HTMLElement.appendChild @ VM155:323
addCalendar @ DateTimeShortcuts.js:224
init @ DateTimeShortcuts.js:45
web服务器是nginx,配置文件:
location /static {
alias /home/django/django_project/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
我也把第二个地址改成了:
alias /home/django/django_project/django_project/static/admin;
但仍然无法正常工作。 (我使用数字海洋作为托管)
- 我没有编辑管理模板
- 我在生产版本中使用了
collectstatic命令 - 用不同的浏览器检查过
- django 在服务器和本地的版本都是 1.11
那么在collectstatic之后我还需要做什么吗?
【问题讨论】:
-
你是对的,静态文件有问题。但很难告诉你是什么,因为这取决于你如何部署它。还要检查你的浏览器调试器,看看哪些请求实际上失败了。
-
你能更新更多信息吗?查看您的 settings.py 静态文件配置并了解您如何部署它会很有帮助。
-
@Daniel 我添加了一些额外的信息。
-
@KlausD。它无法从管理静态文件加载一些文件,如 jquery.js。但我不知道原因。
-
很好,托管怎么样?是 nginx 吗?它是如何配置的?发布访问管理站点时浏览器控制台中显示的内容。
标签: python django django-admin