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

176
Views
La implementación de Flask simple render_template falla

Estoy tratando de hacer un sitio de matraz y hasta ahora está funcionando para imprimir un hola mundo. Cuando trato de pasar de la salida de texto a la salida de una plantilla html simple, el sitio se rompe y aparece el siguiente error.

Este es mi código:

 from flask import render_template, Blueprint recipes_blueprint = Blueprint('recipes', __name__, template_folder='templates') @recipes_blueprint.route('/') def index(): return render_template('list.html')

Y mi list.html es simplemente el siguiente dentro de la carpeta de plantillas:

 <h1>Test</h1>

El error completo está aquí:

 2021-10-16 07:50:53,399: from app import app as application # noqa 2021-10-16 07:50:53,399: 2021-10-16 07:50:53,399: File "/home/jameshiven/mysite/app.py", line 3, in <module> 2021-10-16 07:50:53,399: from products.views import products_bp 2021-10-16 07:50:53,399: 2021-10-16 07:50:53,399: File "/home/jameshiven/mysite/products/views.py", line 12, in <module> 2021-10-16 07:50:53,399: render_template('list.html') 2021-10-16 07:50:53,399: 2021-10-16 07:50:53,399: File "/usr/local/lib/python3.9/site-packages/flask/templating.py", line 146, in render_template 2021-10-16 07:50:53,399: ctx.app.update_template_context(context) 2021-10-16 07:50:53,400:
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Se supone que los planos se registran con la aplicación del matraz para que aparezcan en la aplicación.

Modifica tu código para

 from flask import render_template, Blueprint, Flask recipes_blueprint = Blueprint('recipes', __name__, template_folder='templates') app = Flask(__name__) app.register_blueprint(recipes_blueprint) @app.route('/') def index(): return render_template('list.html') if __name__ == '__main__': app.run()

Algunos ejemplos aquí , aquí

over 4 years ago · Santiago Trujillo Report

0

No proporcionó el mensaje de excepción real, pero supongo que fue:

 AttributeError: 'NoneType' object has no attribute 'app'

Esto se debe a que su función de vista está en mal estado. Cámbialo para que diga:

 @recipes_blueprint.route('/') def index(): return render_template('list.html')

Luego registre su plano con el objeto de la app como sugirió John.

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!