from flask import Flask, render_template, request, flash from wtforms import Form, StringField from wtforms.validators import DataRequired, URL import secrets DEBUG = False app = Flask(__name__) app.config['SECRET_KEY'] = secrets.token_urlsafe(20) class MyForm(Form): url = StringField('url', validators=[DataRequired(), URL(message='Must be a valid URL')]) @app.route('/', methods=['GET', 'POST']) def hello(): # TODO: error handling? form = MyForm(request.form) # print(form.errors) if request.method == 'POST': url = request.form['url'] print("URL: " + url) if form.validate(): flash('OK. Download in progress') else: flash('Error: bad URL') return render_template('index.html', form=form) if __name__ == "__main__": app.run()