1: Session:
fromFlaskImportFlask, url_for, request, render_template, session fromWerkzeug.utilsImportRedirect, Escapeapp= Flask (__name__) @app. Route ('/')defindex ():if 'username' inchsession:return 'logged in as%s'% Escape (session['username']) return 'You aren't logged in'@app. Route ('/login', methods=['GET','POST'])deflogin ():ifRequest.method = ='POST': session['username'] = request.form['username'] returnRedirect (Url_for ('Index')) return " "<form action= "" method= "post" > <p><input type=text name=username> < P><input type=submit value=login> </form>" "@app. Route ('/logout')deflogout ():#Remove the username from the session if it ' s thereSession.pop ('username', None)returnRedirect (Url_for ('Index'))if __name__=='__main__': App.debug=True App.run ()
2: Deploy to a WEB server
Ready to deploy your Flask app? You can immediately deploy to a managed platform to successfully complete the QuickStart, and the following vendors offer free solutions to small projects:
- Deploy Flask on Heroku
- Specific instructions for deploying Flask attached Flask on DotCloud
Other options for managed Flask applications:
- Deploy Flask on Webfaction
- Deploy Flask on Google App Engine
- Share your local server with Localtunnel
If you have your own hosting and are ready to host it yourself, see the Deployment Selection section.
Three Flask Web Development Quick Start