I'm trying to get the data from this html form, through flask and store it in python variables so that I can access and process later.
In the python code I have req = request.form
and that returns a dictionary which contains all the info I need but I can't acces it outside the form_input() function.
Is there anyway I can do this ?
Thanks
python code
from flask import Flask, request, redirect, render_template
app = Flask(__name__)
path = r'C:\Users\tiberiu.ghimbas\PycharmProjects\pythonProject\form.html'
lista = []
app.testing = True
client = app.test_client()
@app.route('/')
def home():
return render_template('form.html')
@app.route('/submit_form', methods=['GET', 'POST'])
def form_input():
if request.method == "POST":
req = request.form
last_name = request.form['lname']
first_name = request.form['fname']
email = request.form['email']
department = request.form['departament']
data_angajare = request.form['data_angajare']
return redirect(request.url)
return render_template('form.html')
if __name__ == "__main__":
app.run()
html
<html>
<head>
<title>Form</title>
</head>
<body>
<form action = "/submit_form" method = "post">
<label for = "fname">First name:</label>
<input type = "text" id = "fname" name = "fname"><br>
<label for = "lname">Last name:</label>
<input type = "text" id = "lname" name = "lname"><br><br>
<label for = "mail">Email:</label>
<input type = "text" id = "mail" name = "email"></input> <br><br>
<input type = "radio" id = "1" name = "departament" value = "Hotel">
<label for = "1">Hotel</label>
<input type = "radio" id = "2" name = "departament" value = "Vanzari">
<label for = "2">Vanzari</label>
<input type = "radio" id = "3" name = "departament" value = "Marketing">
<label for = "3">Marketing</label>
<input type = "radio" id = "4" name = "departament" value = "IT">
<label for = "4">IT</label>
<br>
<br>
<label for = "date">Data angajarii: </label>
<input type = "date" id = "date" name = "data_angajare"> <br><br>
<input type = "submit" value = "submit"></input>
</form>
</body>
</html>