[Python] How to insert HTML Character Entities in Fast HTML? [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I want to display a string that has some spaces together using Fast HTML. I have tried to use the HTML character entity for the space (" " or " ") but none of them are transformed to spaces. Here is a simple example:

    from fasthtml import common as fh
    app = fh.FastHTML()

    @app.get('/mytest')
    def home():
    return fh.Div(
    fh.H1("FastHTML APP"),
    fh.P("My separated        string"),
    )
    print (fh.to_xml(a))
    return a
    fh.serve()


    The HTML displayed is:

    <div>
    <h1>FastHTML APP</h1>
    <p>My separated &nbsp;&nbsp;&nbsp;&#160;&#160;&#160; string</p>
    </div>


    But in the browser I can see it is displayed:

    My separated &nbsp;&nbsp;&nbsp;&#160;&#160;&#160; string

    instead of:

    My separated string

    COMMENT: This question has been proposed as duplicated. I think the problem although similar, is not the same. In this case I am trying to add specifically HTML Character Entities in a paragraph.

    Continue reading...

Compartilhe esta Página