Flask

Preface

This tutorial is adapted from a forum post answered by Krydos, How do I use Flask on the HelioNet forum.
It is worth to note that flask on the Tommy and Johnny servers use python 3.7, and if you want to use flask on python 3.9 you have to be on the Ricky server.

About Flask

Flask is a Python web framework built with a small core and easy-to-extend philosophy. Full Stack Python​

How to setup Flask

Create a folder in public_html called flask
1
/home/username/public_html/flask/
Copied!
In that folder create a .htaccess file:
1
RewriteEngine On
2
RewriteBase /
3
RewriteRule ^(media/.*)$ - [L]
4
RewriteRule ^(admin_media/.*)$ - [L]
5
RewriteRule ^(flask\.wsgi/.*)$ - [L]
6
RewriteRule ^(.*)$ flask/flask.wsgi/$1 [QSA,PT,L]
Copied!
Create a file named flask.wsgi in the flask directory.
1
import os, sys
2
​
3
# edit your username below
4
sys.path.append("/home/username/public_html/flask")
5
​
6
sys.path.insert(0, os.path.dirname(__file__))
7
from myapp import app as application
8
​
9
# make the secret code a little better
10
application.secret_key = 'secret'
Copied!
Create a python script named myapp.py in the flask directory.
1
import sys
2
​
3
from flask import Flask, __version__
4
app = Flask(__name__)
5
application = app
6
​
7
@app.route("/")
8
def hello():
9
return """
10
​
11
HelioHost rules!<br><br>
12
<a href="/flask/python/version/">Python version</a><br>
13
<a href="/flask/flask/version/">Flask version</a>
14
​
15
"""
16
​
17
@app.route("/python/version/")
18
def p_version():
19
return "Python version %s" % sys.version
20
​
21
@app.route("/flask/version/")
22
def f_version():
23
return "Flask version %s" % __version__
24
​
25
if __name__ == "__main__":
26
app.run()
Copied!
Last modified 6mo ago