【问题标题】:Pulling images from a hosting company to django project将图像从托管公司拉到 django 项目
【发布时间】:2022-12-18 03:15:27
【问题描述】:

我最近将我的网站投入生产。我正在使用一家公司在他们的服务器上托管我的项目,除了我上传图片时,一切都运行良好。

上传它自己的作品,它们被正确上传到 base/static/images/images 文件夹。但是网站本身在通过 django admin 上传时试图从 public_html/images/images 文件夹中提取图像。对于从正确的文件夹中提取图像或将图像上传到正确的文件夹,我需要更改什么。以下是我对静态文件的设置。

    STATIC_URL = 'static/'
    MEDIA_URL = 'images/'
    
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static')
    ]
    
    MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

【问题讨论】:

    标签: django static django-staticfiles


    【解决方案1】:

    尝试将其放在您的主 urls.py 文件中:

    from django.contrib.staticfiles.urls import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    
    urlpatterns = [
    
    ]
    
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
    

    【讨论】:

    • 不幸的是,没有什么,也许因为它的上传是托管公司解决的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    相关资源
    最近更新 更多