was just wondering how I would go about formatting text while entering it into my admin page from django in a blog app. I have the very basic code for the article/blog app.
In models.py:
class Article(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
pub_date = models.DateTimeField('date published')
likes = models.IntegerField()
def __str__(self):
return self.title
Is there something that I need to add in the "body" variable? I tried just typing something like
<br>
in the text while typing in the text field while in the django admin page for posting articles. The html file looks like this btw:
<h1>{{ article.title }}</h1>
<p>{{ article.body }}</p>
But no change in the text I entered. Would anybody be able to help? I've been searching and maybe I'm not doing the best job of looking, but I can't seem to find how to do this. Just want it to be simple to edit the text while writing a blog post.
Thank you in advance for any help and/or advice, it is appreciated.
Please try the linebreaks built-in filter. Use it like this:
...
<p>{{ article.body|linebreaks }}</p>
Now in your admin page you could insert new lines as you'd do in any text editor you use.