首页 > 解决方案 > 如何使用 django 和 apache 在文档根文件夹中提供图像

问题描述

我已经使用 apache 部署了一个 django 应用程序。我正在使用一个名为 django-ads 的应用程序,它允许我上传图像。该应用程序将图像转储到 BASE_DIR 文件夹中,因此当图像显示在 html 页面上时,图像 url 为http://ip-address/iphone.jpeg 。

以下是我的 conf 文件的外观:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

WSGIScriptAlias / /var/www/html/mysite/wsgi.py

WSGIDaemonProcess advert-admin python-home=/home/joe/advert-admin/venv 
    python-path=/var/www/html
WSGIProcessGroup advert-admin

<Directory /var/www/html/>
    AllowOverride all
    Require all granted
    Options FollowSymlinks
</Directory>

Alias /static/ /var/www/html/static/

<Directory /var/www/html/static>
    Require all granted
</Directory>

每次加载图像时都会出现 404 错误。

如何使用 Apache 提供 /var/www/html 文件夹中的图像,以便http://ip-address/iphone.jpeg不返回 404?

标签: djangoapache

解决方案


推荐阅读