How can I get the MEDIA_URL from within a Django template?

后端 未结 2 1219
时光取名叫无心
时光取名叫无心 2021-01-21 03:38

I\'m somewhat confused as to how Django operates with static content. Essentially, in the settings.py file, we define MEDIA_URL which points to the URL

2条回答
  •  温柔的废话
    2021-01-21 04:22

    To access STATIC_URL in your templates, make sure django.core.context_processors.static is in TEMPLATE_CONTEXT_PROCESSORS, and that you're using a RequestContext. More details here.

    In addition, static files should be placed under STATIC_URL, not MEDIA_URL, unless it is user-uploaded content.

提交回复
热议问题