dannyxn dannyxn - 5 months ago 31
HTML Question

How to perform html markups on site in Django

Recently I've started to learn Django, I've decided to make
a sample blog website. I've made Post model which creates and publish post. But there's a problem, I've no idea how to attach html markups to my Post object's attribute for instance "text" e.g
I want to bold my text, but instead text, I see "

Here is how I've made Post model:

from django.db import models
from django.utils import timezone

class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
introduction = models.TextField()
text = models.TextField()
created_date = models.DateTimeField(
published_date = models.DateTimeField(
blank=True, null=True)

def publish(self):
self.published_date = timezone.now()

def __str__(self):
return self.title


On your template file use the safe filter like this:

<h1>{{post.title | safe}}</h1>