【发布时间】:2018-02-01 14:36:32
【问题描述】:
我正在尝试提供在 django-admin 中注册的媒体文件。
通过 api 访问图片时出现错误 404 Not found.
我按照推荐的documentation进行了配置,但是在heroku中不起作用。
settings.py
import os
from decouple import config, Csv
from dj_database_url import parse as dburl
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())
default_dburl = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = {
'default': config('DATABASE_URL', default=default_dburl, cast=dburl),
}
(...)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
wsgi.py
import os
from dj_static import Cling, MediaCling
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "integrafundaj.settings")
application = Cling(MediaCling(get_wsgi_application()))
requirements.txt
dj-database-url==0.4.2
dj-static==0.0.6
Django==1.11.3
djangorestframework==3.7.7
easy-thumbnails==2.4.2
olefile==0.44
Pillow==4.3.0
python-decouple==3.1
pytz==2017.3
static3==0.7.0
Unidecode==0.4.21
gunicorn==19.4.1
psycopg2==2.7.1
【问题讨论】: