some1else2
some1else2

Reputation: 25

Image between text in Django

I'm trying to figure out how I can place an image between text in a blog post in Django. I first thought of using something like the urlize filter ({ blog.body | urlize }) that would allow me to include a link for the image on the text body and then render the image on the post, but alas there is no filter for that. Or at least not that I know of.

I then realized it would be much more preferable if I could place the image inside the admin panel itself, in the form of an inline command, like it is done here: https://pythonhosted.org/django-inline-media/

What is an easy implementation of this that wouldn't require me using the whole package there? Any help is greatly appreciated.

Upvotes: 0

Views: 257

Answers (1)

Srishti Ahuja
Srishti Ahuja

Reputation: 191

You can always use the safe filter and use an img tag between your text.

For eg text added in your admin panel can go like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. 
<img src="">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur.

Now let's assume that you have passed this text under the name txt in the context dictionary in your views.py file. Then this text can be rendered as follows:

{txt | safe}

This way you can add an image anywhere you want in the text and dynamically render it.

Upvotes: 1

Related Questions