为什么Django的管理面板在生产版本中出现了不同?

2024-10-02 10:34:31 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我不知道这是我的问题还是别人也有。我的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/'

关于路径:

^{pr2}$

运行管理面板时控制台日志显示与管理面板相关的静态文件如下所示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之后还要做其他事情吗?在


Tags: djangohttpsprojectcomgetnetadmininit
2条回答

collectstatic命令将静态文件从管理站点和其他包复制到静态目录中,这样您就不需要问题中显示的第二个location块。在

也会改变

location /static {
    alias /home/django/django_project/django_project/static;
}

^{pr2}$

是的,现在您需要为在collectstatic之后创建的static/admin目录设置权限命令。输入项目的根目录(在生产环境中),运行以下命令。在

苏多周恩-R用户:www data static在

其中user=系统的当前用户。在

相关问题 更多 >

    热门问题