Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
Flask does not recognize controller when using `url_for()` in HTML form

When trying to implement a basic form I get the following error message: werkzeug.routing.BuildError: Could not build url for endpoint 'finder.search'. Did you mean 'finder.static' instead?, the index.html page does not even load because of this error.

Directory

Steam
  SteamFinder
    static
      style.css
    templates
      index.html
      result.html
    __init__.py
    finder.py
  venv

init.py

from flask import Flask
from flask.templating import render_template


def create_app():
    # create and configure the app
    app = Flask(__name__)

    from . import finder
    app.register_blueprint(finder.bp)

    @app.route("/")
    def home():
        return render_template("index.html")

    return app

finder.py

from flask import Blueprint, request
from flask.templating import render_template

bp = Blueprint("finder", __name__, template_folder="templates", static_folder="static")

bp.route("/search", methods=["POST"])
def search():
    query = request.form["query"]
    print(query)
    return render_template("result.html")

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../static/style.css"/>
    <title>Home</title>
</head>
<body>

    <form action="{{ url_for('finder.search') }}" method="post">
        <label for="query">Query:</label><br>
        <input type="text" id="query" name="query"><br>
        <input type="submit">
    </form>
    
</body>
</html>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You cannot use the url_for directly in the template, Jinja cannot process it. You should pass it as a variable to the render_template function and use that variable name in the jinja block.

Example:

return render_template("index.html", form_action_url=url_for('finder.search'))

and the form's action will be:

    <form action="{{ form_action_url }}" method="post">
        <label for="query">Query:</label><br>
        <input type="text" id="query" name="query"><br>
        <input type="submit">
    </form>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda