📗
Heliohost Wiki
  • Home
  • Hosting
    • What is HelioHost?
    • What HelioHost Offers
    • What HelioHost is Not
    • What is HelioNet?
    • Signing up
    • Why was my account suspended?
    • Terms of Service
  • Accounts
    • International Countries
    • Moving your account
    • Suspension Policy
  • cPanel and Management
    • Uploading Files
    • Changing Your Main Domain
    • Creating MySQL Databases via cPanel
    • Parked, Addon and Sub Domains
    • Using SSL
  • Tutorials
    • Discord Bot
    • Django
    • Flask
    • Installing Free SSL Certificate via cPanel (that autorenews)
    • Ghost CMS
    • Golang as CGI
    • How to Access cPanel
    • Node.js
    • Perl
    • Python
    • Ruby on Rails
  • FAQ
  • Servers
    • Physical
      • Charlie
      • Eddie
      • Sparkie
      • Stevie
    • Virtual
      • Brody
      • Cody
      • Johnny
      • Lily
      • Ricky
      • Tommy
  • Features
    • ASP.NET
    • cPanel
    • Java/JSP
    • PHP
    • PostgreSQL
    • Python
    • Softaculous
    • Sqlite
    • Storage
    • Unlimited Bandwidth
    • Unlimited Email Accounts
  • Miscellaneous
    • Clear Your Cache
    • Contributing
    • Server Load and Uptime
    • Staff
      • Ashoat
      • Krydos
      • Wolstech
Powered by GitBook
On this page
  • Preface
  • About Flask
  • How to setup Flask

Was this helpful?

  1. Tutorials

Flask

PreviousDjangoNextInstalling Free SSL Certificate via cPanel (that autorenews)

Last updated 4 years ago

Was this helpful?

Preface

This tutorial is adapted from a forum post answered by Krydos, 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 2.7 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.

How to setup Flask

Create a folder in public_html called flask

/home/username/public_html/flask/

In that folder create a .htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(flask\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ flask/flask.wsgi/$1 [QSA,PT,L]

Create a file named flask.wsgi in the flask directory.

import os, sys

# edit your username below
sys.path.append("/home/username/public_html/flask")

sys.path.insert(0, os.path.dirname(__file__))
from myapp import app as application

# make the secret code a little better
application.secret_key = 'secret'

Create a python script named myapp.py in the flask directory.

import sys

from flask import Flask, __version__
app = Flask(__name__)
application = app

@app.route("/")
def hello():
  return """

    HelioHost rules!<br><br>
    <a href="/flask/python/version/">Python version</a><br>
    <a href="/flask/flask/version/">Flask version</a>

  """

@app.route("/python/version/")
def p_version():
  return "Python version %s" % sys.version

@app.route("/flask/version/")
def f_version():
  return "Flask version %s" % __version__

if __name__ == "__main__":
  app.run()
How do I use Flask
Full Stack Python