I want to create a blog. I want to create blog content in admin panel and render the blog content with HTML format.
models.py
class Blog(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_created = models.DateField(auto_now_add=True)
def __str__(self):
return self.title
In admin panel : Create blog content with HTML format in admin
In template:
{% extends 'base.html' %}
{% block content %}
<h1>{{ blog.title }}</h1>
<p>{{ blog.content }}</p>
{% endblock content %}
Is there any template tags, model field, or anything to do this?
You can do this by simply using the built in safe template tag.
In your template:
{% extends 'base.html' %}
{% block content %}
<h1>{{ blog.title }}</h1>
<p>{{ blog.content | safe }}</p>
{% endblock content %}
check the docs for the same here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With