Answer the question
In order to leave comments, you need to log in
How to correctly configure the distribution of MEDIA files in the Django settings?
I can not set up the distribution of MEDIA
settings.py
MEDIA_ROOT = os.path.join(BASE_DIR, "files", "media")
MEDIA_URL = "/media/"
STATIC_ROOT = os.path.join(BASE_DIR, "files", "static")
STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "templates", "static"),
]
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
urls.py
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
<img src="/media/img.png">
Answer the question
In order to leave comments, you need to log in
The problem was in the urls.
it was like this:
urlpatterns = patterns (
url(r'', ListView.as_view(template_name='homepage.html'),, name='index')
)
urlpatterns = (
url(r'^$', ListView.as_view(template_name='homepage.html'), name='index')
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question