I deployed a website with django. it servs all static files but doesn't serve user-uploaded files.
this is my settings.py
and urls.py
:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = False
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticroot')
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
MEDIA_URL = '/files/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploaded_files')
and the urls.py
:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', Index.as_view(), name='index'),
]
In the pages, it prints user-uploaded files addresses correctly, but doesn't show them anf when I click on the links, it shows me 404 page. I use last version of nginx that I took from nginx repositories. the version 1.12. is it related to django or webserver(nginx+ gunicorn)? and how can I solve the problem?
Update
When I change the MEDIA_URL
and DEBUG
to True, for the first time it works and serves user-uploaded files, but if I refresh the page, then it doesn't work! what's the problem??
you must define in urls.py