keywords
Flask Route Debug
Checkout
from flask import Flask, request, render_template, url_for, make_response
from werkzeug.utils import secure_filename
from os import path
app = Flask(__name__)
app.config.update({
'DEBUG': True
})
@app.route('/')
def hey():
# return 'Hello World'
response = make_response(render_template('index.html', title='Carson'))
response.set_cookie('username', '')
return response
@app.route('/login', method=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
return render_template('login.html', method=request.method)
@app.route('/about')
def about():
return 'About'
@app.route('/<int:user_id'>)
@app.route('/<float:user_id'>)
def user(user_id):
return 'User: %d' % user_id
@app.route('/<path:load>')
def pwd(load):
return 'load'
@app.route('/upload', methods=['GET','POST'])
def upload():
if request.method == 'POST':
f = request.files['file']
base_path = path.abspath(path.dirname(__file__))
upload_path = path.join(base_path, 'static/uploads')
f.save(upload_path, secure_filename(f.filename))
return redirect(url_for('upload'))
return render_template('uploads.html')
if __name__ == '__main__':
app.run(host='121.0.0.1', port=9999, debug=True)