template tag in html not loaded from admin panel

Hi,
I’m having the below issue…
I have no problem when I include the following line directly into a html file. Everything renders/loads perfect:

<img src="{% static 'assets/img/photos/about14.jpg' %}" alt="image">

When I want to do the same thing from admin panel I’m having problem. When I check the page source it is not rendered properly and seen as:

<img src="{% static 'assets/img/photos/about14.jpg' %}" alt="image">

I tried the following in html file …

{% autoescape off %}
{{ single_post.blog_body }}
{% endautoescape %}

… but no luck. Can you pls share your opinion. Thanks.

Welcome @seabiscuit !

We’re going to need more details about what you’re trying to do here. What are you doing to do this?

What does your model look like? What does your ModelAdmin class look like?

Side note: The admin is not an html page editor. It’s not clear what your objective is.

Hi Ken,
I was initially trying to use Summernote. After facing this issue, I thought it may be related with Summernote so I changed the ModelAdmin to the following:

class BlogAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'category', 'author', 'status', 'is_featured', 'created_on', 'updated_on',)
    search_fields = ('id', 'title', 'category__category_name', 'status')
    list_editable = ('is_featured',)
    # summernote_fields = ('blog_body',)

I’m simply trying to include “blog_body” field into the “blog-post.html” template directly from admin panel. I was partially successful with Summernote but even with it I couldn’t get the img tag loaded successfully. This was before switching to plain admin panel for testing.

But how are you rendering the blog-post.html template within the admin?

I’m not rendering it from admin. I update the blog object (blog_body field) from admin. Then I render blog-post.html as usual:

`path('<slug:blog_slug>/', BlogViews.single_post, name='single_post'),`

Ok, I think I’m starting to understand.

If I’m following you, the real issue here is that you have template tags within data being rendered within a template.

If this is the issue, then no, the Django template engine will not perform these recursive renderings for you.

If you’ve got data being rendered, and this data also needs to be rendered, you need to render that data yourself and pass that rendered text as the data into the context of the template being rendered.

I see …
All I wanted to make all the css formatting and html parts of the blog_body field from admin panel and include this field into blog_post.html as: {{ single_post.blog_body | safe }}.

This was going to really make my process easier. I partially managed this with Summernote. I was able to send the blog_body to blog_post.html by using {{ single_post.blog_body | safe }} in blog_post.html. Everything was looking great except <img src="{% static 'assets/img/photos/about14.jpg' %}" alt="image">.

There is no remedy for this I guess. Thank you for your time Ken.
I really appreciate your quick response and directing me to the right path.

You can use Data_URLs see more in Data URLs - HTTP | MDN

For example:

<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
    AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
        9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

You can discover the base64 with tools like:

Hey thank you so much. That’s a neat way around the issue. I’ll explore on this. :grinning: