D
D
Dg_Mg2018-03-23 15:39:44
Flask
Dg_Mg, 2018-03-23 15:39:44

How to run a python script by passing it a calendar value in Flask?

Good day.
It is necessary that the user on the main page indicates the date in the calendar and clicks the submit button. After that, the script (test.py) was launched on the server, which accepted the date as str (for example) and executed. The problem is that I couldn't find how to execute the script with the passed parameter in Flask itself.
Please share the link, or suggest how to implement it :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Boyko, 2018-03-23
@Dg_Mg

Um, I don't quite understand what "execute a script" means.
Perhaps you mean "call a function"?
Then form.birth_date.data must be passed to the function.
For example:

class EditUser(FlaskForm):
    birth_date = DateField('Birthday Date', description='YYYY-MM-DD', format='%Y-%m-%d')
    submit = SubmitField('Edit User')

def myfunc(birthday):
    print(birthday)

@app.route('/edit', methods=['GET', 'POST'])
def edit_account():
    form = EditUser()
    if form.validate_on_submit():
        myfunc(str(form.birth_date.data))

Where exactly myfunc() lives does not matter, it can be imported within the project

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question