Задать вопрос

Тел: +7 965 3737 888

439

Просмотров

2

Ответов

Use MEDIA_URL in flatpages

<p>This is a template filter to enable the use of the MEDIA_URL setting in content from the flatpages database table.  It searches for {{ MEDIA_URL }} and replaces it with that found in your settings.</p>
<p>Note: To set up, drop the above code into a file called media_url.py in your templatetags directory in one of your INSTALLED_APPS, and add the filter to your flatpages template like so:</p>
{% load media_url %}
{{ flatpage.content|media_url }}

Вопрос полезен? Да0/Нет0
file_3157.py(396.0б)
None

Ответы (2):

Ответkylefox:24.03.2008
Ответ полезен? Да0/Нет0

Gotcha.

Ответrobhudson:23.03.2008
Ответ полезен? Да0/Нет0

@kylefox: I think you missed the point of this snippet... since the content comes from the database via flatpage's content field, the interpretation of any Django template code doesn't happen -- it only happens on actual templates themselves. Since this is content being displayed in the template, Django isn't going to run the content through a Template processor.

So all this snippet does is search and replace {{ MEDIA_URL }} in the content with its appropriate setting value. A context processor isn't going to be able to do that.