Reputation: 31
I'm using Django on pythonanywhere to create a webapp. I'm trying to access a file in my media folder by going to http://thedstrat94.pythonanywhere.com/media/example.png. I only get a 'Not Found' error
My Url Patterns in urls.py looks right:
urlpatterns = [
path('admin/', admin.site.urls), #url(r'^admin/', admin.site.urls),
path('', views.index, name = "index"),
path('about/',views.about,name = "about"),
path('articles/',include("article.urls")),
path('user/',include("user.urls")),
]
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
My settings.py file looks right:
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Upvotes: 1
Views: 423
Reputation: 13047
Django is not made to serve media files in production environment.
Django serves media files only when Debug=True
when running application locally in Debug mode.
That means with the above settings you can't serve the media files in production.
Solutions:
Upvotes: 1