Sunday, August 30, 2015

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

So you are saying I should alter the models save method to do a search and replace on the entry field?

On Sunday, 30 August 2015 14:03:18 UTC-7, monoBOT monoBOT wrote:
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 <dennis...@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...@googlegroups.com.
To post to this group, send email to django...@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/99e5bce9-1537-4bd1-99b1-a2b6e14aa64b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment