Django: MEDIA_URL not set in template

后端 未结 2 1418
说谎
说谎 2021-02-05 19:32

I\'ve read a lot of question and article but can\'t find what I\'m missing.

Here is my conf :

settings.py

MEDIA_ROOT = os.path.j         


        
2条回答
  •  失恋的感觉
    2021-02-05 20:31

    You need to define the django.template.context_processors.media template context processor in your settings for MEDIA_URL variable to be present in the template context.

    If this processor is enabled, every RequestContext will contain a variable MEDIA_URL, providing the value of the MEDIA_URL setting.

    Including this in your settings will include MEDIA_URL in the template context. It is not included by default in Django 1.8 settings. We need to set it explicitly.

    context_processors = [
        ...
        'django.template.context_processors.media', # set this explicitly
    ]
    

提交回复
热议问题