djangodjango-modelsdjango-templatesdjango-admindjango-views

Adding line breaks and headers in django's admin interface


I have created a model like so

class Post(models.Model):
    title_of_post = models.CharField(max_length=100)
    actual_post = models.TextField()

and I put this model in the admin interface and enabled the admin interface. Now, when I go to 127.0.0.1/admin/ and sign in, I can add this model. The posts created in the Post model can be seen on the homepage (127.0.0.1) so say my "title_of_post" is "title" and my "actual_post" is "the actual post", if I go to 127.0.0.1 I can see both the title and actual post on the homepage. The problem is, when I am in the admin interface and in the actual_post text box / TextField section, suppose I write this.

Something.
else

It would not recognize that I pushed the enter key after the period. I tried

Something. <br>
else

but that also didn't work. It does not go on a new line after the period. Is there any way to go to the next line when inputting information from the text box / TextField in the Django admin interface? Is there any way to put headers from the admin interface, not from the template? Essentially, I want to be able to create this HTML from the admin interface.

<h1>Something.</h1> <br>
else

Solution

  • in order to show html inside a property, you need to place like this in your template:

    {{ post.actual_post|safe }}
    

    the safe template filter its good for not escaping html tags inside your template.

    And this will print as:

    Something
    else
    

    intead of:

    Something <br /> else