#๐Ÿ”’ problem with jinja and flask

6 messages ยท Page 1 of 1 (latest)

paper matrix
#

i got this code with flask:

def home(number):
   return render_template("home.html", numberJinja=int(number))

@app.route("/", methods=["POST", "GET"])
def number():
   if request.method == "POST":
      numberFromForm = request.form["num"]
      return redirect(url_for("home", number = numberFromForm))
   else:
      return render_template("number.html")```
templates/home.html
```html
<!DOCTYPE html>
<body>
    {% for i in range(numberJinja) %}
    <h1>CIAO</h1>
    {% endfor %}
</body>
</html>```
templates/number.html
```html
<!DOCTYPE html>
<body>
    <form action="#" method="post">
        <input type="text" name="num">
        <input type="submit" value="submit">
    </form>
</body>
</html>```
not working...
ERROR: `werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'home' with values ['number']. Did you mean 'number' instead?`
visual ridgeBOT
#

@paper matrix

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

subtle kraken
#

the home function doesn't have a decorator to be a route

#

so url_for naturally fails

visual ridgeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.