如何处理Django模板中无法引用MEDIA_URL的问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计449个文字,预计阅读时间需要2分钟。
配置如下:TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.core.context_processors.media', # 将MEDIA_URL配置在template中,这样在template下面就可以使用MEDIA_URL了 ], }, },]
补充知识:在django中使用MEDIA_URL,可以在template中直接引用配置好的媒体文件路径。
本文共计449个文字,预计阅读时间需要2分钟。
配置如下:TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.core.context_processors.media', # 将MEDIA_URL配置在template中,这样在template下面就可以使用MEDIA_URL了 ], }, },]
补充知识:在django中使用MEDIA_URL,可以在template中直接引用配置好的媒体文件路径。

