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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b33410-2be71.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b33410-2be71.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?