settings.py
STATIC_URL = 'static/' # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' STATICFILES_DIRS = [ BASE_DIR / "static", BASE_DIR / "media" ] # STATIC_ROOT = os.path.join(BASE_DIR, '/static') MEDIA_URL = 'media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py
urlpatterns = [ path('admin/', admin.site.urls), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
标签:settings,URL,media,static,MEDIA,DIR,图片 From: https://www.cnblogs.com/python100/p/18002744