Can not create media folder in Django Project

Viewed 1750

Media folder is not getting created when I run the server. I am working in localhost.

You can see the urls.py and settings.py code below.

I added 'django.template.context_processors.media' to the templates. My Django Version is 2.0.3 and I am using Python 3.6.8.

When I run the code, media folder should be created automatically. How can I fix that issue?

    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media') #settings.py

    urlpatterns = [
    path('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) #urls.py
1 Answers

For a media file to be created,you need to add a slash after 'media' in the MEDIA_ROOT

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

instead of:

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Related