I
I
ivanesi2014-07-18 14:15:54
Flask
ivanesi, 2014-07-18 14:15:54

How to process data from a form using Python (flask)?

Good afternoon.

There is an html with a form and script.py. Flask framework.
How to pass data from input to a function as an argument?
And how to output the data parsed by the script back to html?

thank.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ivanesi, 2014-07-18
@ivanesi

I found the answer to the first half of the question here: stackoverflow.com/questions/12277933/send-data-fro...

S
Sergey Paramonov, 2014-07-18
@varagian

You can pass it to a function like this (the code of one of the www.habr-analytics.com/user functions )

@app.route('/userfig/<name>/<datatype>')
def userfig(name,datatype):
  name = str(name.strip().lower())
  # unsupported operation
  if datatype not in datatypes:
    return
    .....

You can pass back to the form as follows (from the same place)
@app.route('/user/', methods=['GET'])
def user():
  name = request.args.get('name')
  datatype = request.args.get('datatype')
  data_title = None
  if datatype in datatypes:
    data_title = datatypes_to_title[datatype]
  return render_template("user.html", usernameform=usernameform, name=name, datatype=datatype, datatypes=datatypes, data_title = data_title)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question