How to separate lines in django text_Field model?

Viewed 33

I have written the following code in my models.py file:

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
# Create your models here.

class Post(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    genere = models.CharField(max_length=50, default='')

    def __str__(self):
        return f'{self.title} by {self.author}'

In my views.py file I have written:

from django.shortcuts import render
from .models import Post
from django.views.generic import ListView

class PostListView(ListView):
    model = Post
    template_name = "blog/index.html"
    context_object_name = "posts"
    ordering = ["-date_posted"]

In my index.html I have written:

{% extends "blog/base.html" %}
{% load static %}
{% block content %}
    {% for post in posts %}
            <article class="col-12 col-md-6 tm-post">
                <hr class="tm-hr-primary">
                <a href="{% url 'blog-detail' post.id %}" class="effect-lily tm-post-link tm-pt-60">
                    <div class="tm-post-link-inner">
                        <img src="{% static 'img/img-01.jpg' %}" alt="Image" class="img-fluid">
                    </div>
                    <span class="position-absolute tm-new-badge">New</span>
                    <h2 class="tm-pt-30 tm-color-primary tm-post-title">{{ post.title }}</h2>
                </a>
                <p class="tm-pt-30">
                    {{ post.content|safe|truncatewords:"30"|linebreaks }}
                </p>
                <div class="d-flex justify-content-between tm-pt-45">
                    <span class="tm-color-primary">{{ post.genere }}</span>
                    <span class="tm-color-primary">{{ post.date_posted|date:'N j,Y' }}</span>
                </div>
                <hr>
                <div class="d-flex justify-content-between">
                    <span>36 comments</span>
                    <span>by {{ post.author }}</span>
                </div>
            </article>
        {% endfor %}
{% endblock %}

Suppose if I add the following things in my post.content:

laborum deserunt do excepteur minim sint reprehenderit dolor id mollit
pariatur occaecat quis in qui
pariatur occaecat quis in qui
pariatur occaecat quis in qui

So, it is displayed like:

laborum deserunt do excepteur minim sint reprehenderit dolor id mollit pariatur occaecat quis in qui pariatur occaecat quis in qui pariatur occaecat quis in qui

What can I do to resolve this issue?

0 Answers
Related