With Djangoclass-based viewI am making a blog application using.
For decorationdjango-bootstrap4I am using, but I am thinking of making it a specification that allows you to enter multiple lines in the input form.

The problem i am having

textareaWith elementscreate.htmlI created a file, but the text is output in one line on the destination blog itself.

Related source code


{% extends "base.html"%}
{% load bootstrap4%}
{% block title%} Newly created {% endblock%}
{% block content%}
<form action = "" method = "POST">
  {% csrf_token%}
          <input type = "text" name ='title' placeholder = "title">
          <textarea name ='content' rows = "5" placeholder = "content"></textarea>
          <button type = "submit">Create</button>
{% endblock%}


<! DOCTYPE html>
{% load bootstrap4%}
{% bootstrap_css%}
{% bootstrap_javascript jquery ='slim'%}
  <meta charset = "utf-8">
  <meta http-equiv = "X-UA-Compatible" content = "IE = edge">
  <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
  <title>{% block title%} {% endblock%}</title>
    {# --- css --- #}
    {% block extra_css%} {% endblock%}
      {% block content%} {% endblock%}
    {# --- js --- #}
    {% block extra_js%} {% endblock%}


from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView, CreateView, DeleteView
from .models import BlogModel

class BlogList (ListView):
    "" "List display" ""
    template_name ='list.html'
    model = BlogModel
class BlogDetail (DetailView):
    """ Detail View """
    template_name ='detail.html'
    model = BlogModel
class BlogCreate (CreateView):
    "" "Article creation" ""
    template_name ='create.html'
    model = BlogModel
    fields = ('title','content')
    success_url = reverse_lazy ('list')


from django.db import models

class BlogModel (models.Model):
    title = models.CharField (max_length = 100)
    content = models.TextField ()
    postdate = models.DateField (auto_now_add = True)
    def __str __ (self):
        return self.title
  • Answer # 1

    I created a create.html file using the textarea element, but the text is output in one line on the destination blog itself.

    Since the line break via the textarea is a line break code, it is not a line break in the browser when viewed as HTML.

    I don't know if it's correct because there is no template for the person displaying the blog,
    Django has a filter that converts line breaks to
    tags for HTML, so
    If you are not using it, please try it.

    Example of use

    {{article.content | linebreaks}}