简体   繁体   中英

Flask Form Action is not referring to the variable

I have a form and am passing the variable as below using Jinja template

<form action = "/user_data/{{period}}" method="POST">

It is not redirecting required page /user_data/Oct-2022 But while just using {{period}} for testing in html page, variable is returning the result as Oct-2022. Not sure why the same variable is not getting passed in the form action.

Variable is printing as below in html page,

{{period}}

在此处输入图像描述

But it is not printing in the form,

<form action = "/user_data/{{period}}" method="POST">

This is the route method,

@app.route("/user_listing/<period>", methods = ['POST', 'GET'])
def user_data(period):
....
....
return render_template('user_data.html', period=period)

First we imported the Flask class. An instance of this class will be our WSGI application.

Next we create an instance of this class. The first argument is the name of the application's module or package. If you are using a single module (as in this example), you should use name because depending on if it's started as application or imported as module the name will be different (' main ' versus the actual import name). This is needed so that Flask knows where to look for templates, static files, and so on. For more information have a look at the Flask documentation.

We then use the route() decorator to tell Flask what URL should trigger our function.

The function is given a name which is also used to generate URLs for that particular function, and returns the message we want to display in the user's browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM