【问题标题】:Django - resource was not found on this server on productionDjango - 在此服务器上未在生产中找到资源
【发布时间】:2022-01-18 02:39:16
【问题描述】:

我正在尝试访问 django-import-export-celery 模块中使用的这些文件:

我可以在本地看到我的看法:

但它没有显示在我的生产服务器上:

这是我的urlpattern

urlpatterns = static(
    settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
) + [

    # favicon
    path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url('img/Dalmore-Group-16-16.png'))),
    # debug
    path('__debug__/', include(debug_toolbar.urls)),
    url(r'^', admin.site.urls),

] 

我的settings.py 有:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

更新

我在日志中收到此错误:

tail /var/log/gunicorn.err.log
WARNING:django.request:Not Found: /media/django-import-export-celery-import-change-summaries/new1_1_1hRlmBz_ubIptVv_St8xqbE_1_z2_PGH9e4O.html

即使它存在:

ls -A media/django-import-export-celery-import-change-summaries/
new1_1_1hRlmBz_ubIptVv_St8xqbE_1_z2_PGH9e4O.html

【问题讨论】:

    标签: django nginx django-import-export


    【解决方案1】:

    我添加了这个:

    location /media/ { 
        root /home/ubuntu/dalmoreportal;
    } 
    

    /etc/nginx/sites-available/django.conf

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 2020-07-28
      • 2018-05-14
      • 2021-03-07
      • 2016-11-02
      • 2015-05-17
      • 2017-05-09
      • 2014-09-21
      • 2021-09-10
      相关资源
      最近更新 更多