The problem of using summernote,MEDIA path in django background

topic description

DEBUG = False cannot find the picture path, other style files can be loaded

setting.py file

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = False
STATIC_URL = "/static/"
if DEBUG:
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
    ]
else:
    STATIC_ROOT = os.path.join(BASE_DIR, "static")

MEDIA_URL = "/media/"

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

routing information

urlpatterns = [
    ...
    path("summernote/", include("django_summernote.urls")),
    path("archives/<str:year>/<str:month>", blog_views.archives, name="archives"),
    path("category/<str:id>", blog_views.category, name="category"),
]

-sharp  DEBUG = False
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
else:
    urlpatterns += [
        url(r"^static/(?P<path>.*)$", serve,
            {"document_root": settings.STATIC_ROOT}),
    ]

clipboard.png

Directory structure
the problems related to searching on the Internet have been tried but have not been solved. It can only be displayed normally when DEBUG = True

as a beginner, I don"t quite understand

May.09,2021
When

debug=False, the development server, the server on which python manage.py runserver runs, will not handle static resources, so it cannot be found.
static resources need to be maintained using tools such as nginx or apache.


if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
else:
    urlpatterns += [
        url(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
        url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}), -sharp MEDIA_URL
    ]

the effect you set above is MEDIA_ROOT:
project/static/media/

final generated MEDIA_URL:
/ media/static/media/

it is stipulated in the old version of Django that media and static do not seem to be in the same directory.

Menu