R
R
Ravenswood2021-08-12 11:23:35
HTML
Ravenswood, 2021-08-12 11:23:35

How to split a line in html using python?

description= (
    "Примеры:"
    "Пример 1"
    "Пример 2"
)

I have such code. \n serves as a line break so that everything is not on one line in python. But when I use a cycle in HTML to transfer the contents of description, there is no line break. \n does not work (only a space is put), the br tag just writes. No tags/escaped br(<br>) helped.
Where should I insert something so that I get it on the site?

Expected Result:
Примеры:
Пример 1
Пример 2


Actual result:
Примеры: Пример 1 Пример 2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-08-12
@Ravenswood

description= (
    "Примеры:<br/>"
    "Пример 1<br/>"
    "Пример 2<br/>"
)

And something like this in the template - does not help?
{{ description|safe }}

S
Sergey Karbivnichy, 2021-08-12
@hottabxp

Auto-escaping is the automatic escaping of special characters. The special characters in HTML (and also in XML and XHTML) are &, >, <, ", and '. Since these characters have special meaning in documents, they must be replaced by so-called "entities" for use in text. If not to do this, this can not only affect the user's inability to use these characters, but also lead to security problems (see xss).However
, sometimes in templates it may be necessary to disable auto-escaping.This may be necessary if you want to explicitly insert an HTML fragment into the pages if the snippet came from a secure HTML generation system, such as a markdown to HTML converter There
are three ways to achieve this:
In Python code, wrap an HTML string in a Markup object before passing it to the template. This is the recommended way.
Inside a template, using the |safe filter to explicitly mark a string as safe HTML ({{ myvariable|safe }})
Temporarily disable the auto-escaping system.
To disable the auto-escaping system in templates, you can use the {% autoescape %} block:

{% autoescape false %}
    <p>autoescaping is disabled here
    <p>{{ will_not_be_escaped }}
{% endautoescape %}

Be careful and always watch the variables you put in this block.
Source - Auto Shield Control

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question