Created
July 3, 2017 23:05
-
-
Save Pk13055/dcf8222179f318f03ef2f44a1b539b16 to your computer and use it in GitHub Desktop.
Python Flask App (simple SPA, no modules)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, redirect, url_for, render_template | |
import sys, os | |
# this creates our Flask app | |
app = Flask(__name__) | |
# define all your routes here | |
@app.route('/', methods = ['POST', 'GET']) | |
def home(): | |
if request.method == 'GET': | |
title = "Main Page" | |
data = "Hello" | |
return render_template('main.html.j2', title = title, data = data) | |
# this is the port assignment and app running; do not change anything here | |
def main(): | |
port = 8000 | |
try: | |
port = int(sys.argv[1]) | |
except: | |
pass | |
app.run(debug = True, port = port, host = '127.0.0.1') | |
if __name__ == '__main__': | |
main() |
You have to additionally create a templates folder that will house all your templates, viz. main.html.j2 and so on. Remember to name them with the .j2
extension so as to have proper indentation and syntax highlighting
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple Python 3.x implementation of a flask app
Instructions
app.py
with your preferred python3.x versionpython3.6 app.py <port>
locahost:<port>/
Adding models