Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
Mostrar respuesta fastapi (tupla) en un área de texto html

Aquí hay un pequeño ejemplo para comenzar con fastapi:

principal.py

 from typing import Optional from fastapi import FastAPI, Request, Form from fastapi.templating import Jinja2Templates app = FastAPI() templates = Jinja2Templates(directory='./') @app.get("/") def index(): return "Hello World" @app.get("/item/{text}") def get_item(text: str): return {"result": tuple(['Hi', 'hello'])} @app.get("/form") def form(request: Request): result = "" return templates.TemplateResponse('form.html', context={'request': request, 'result': result}) @app.post("/form") def form(request: Request, text: str=Form(...)): result = ['Hello', 'Hi', 'Bye'] # to simplify the example return templates.TemplateResponse('form.html', context={'request': request, 'result': tuple(result)})

formulario.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Small example</title> </head> <body> <form method="post"> <label for="text">Input text:</label> <br> <textarea id="text" name="text" rows="12" cols="50"></textarea> <br/> <input type="submit" value="Submit"> </form> <br></br> <form method="post"> <label for="text">Result:</label> <br> <textarea id="result" name="result" rows="12" cols="50"> {{ result }} </textarea> <br/> </form> </body> </html>

Aquí obtengo el resultado en el área de texto como: ('Hola', 'Hola', 'Adiós')

Lo que necesito es mostrarlo línea por línea en el área de texto de resultados :

Hola.

Hola.

Adiós.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Podrías recorrer la tupla:

 <textarea id="result" name="result" rows="12" cols="50"> {% for i in result %} {{ i }} {% endfor %} </textarea>

También puede escribir el aobve en una línea, ya que lo anterior no parece alinear el texto a la izquierda, a menos que cambie todo el código de python a la izquierda. Usar junto con &#13;&#10; , como se describe aquí , para agregar saltos de línea entre los elementos.

 <textarea id="result" name="result" rows="12" cols="50">{% for i in result %}{{ i }}&#13;&#10;{% endfor %}</textarea>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!