import os MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_URL = "/media/"
Configure routing path
from django.urls import path, re_path urlpatterns = [ re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}, name='media'), # ModelForm Upload path('upload/', upload.upload_modal_form), ]
It should be noted that If you need to upload files form Forms This attribute is required enctype="multipart/form-data", Otherwise, you can only accept the file name
{% extends 'layout.html' %} {% block content%} <div class=