Sunday, August 30, 2015

Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

You can import your any part of your settings into the model.py file and then insert it

like this:

from django.conf import MEDIA_URL


2015-08-30 20:43 GMT+01:00 Dennis Marwood <dennismarwood@gmail.com>:
Hello,

I have a seemingly straight forward and likely common issue. But there is no obvious way that I am seeing to make it work.

I have a Blog model with a text field called entry. I want to put something like

<img src="{{ MEDIA_URL }}/images/my_image.jpg">

into the blog post. So Blog.entry would contain it. Then I use the template to display my blog post like

{% for post in posts %} <p>{{ post.entry }}</p> {% endfor %}

But the template does not process {{ MEDIA_URL }}. It just sees it as a string and prints it exactly as passed in.

How do I get the template to treat {{ }} in my entry as a variable? How can I get that value substituted? I have used a custom template filter in the past. But this has got to be a very common use case. It seems like there would be some built in django way to get this to work?

Thanks,
Dennis

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BxOsGDaVDWA_xeP%2BwBSdYE%2BeMH6NcZUoDRXA6fJ%2BzOhrwhCCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment