1. Startseite
  2. Python
  3. Flask Schnellstart

Flask Schnellstart

Übersicht

Flask is a Python microframework for building web sites with minimal overhead. Think of it as a lightweight version of Django with fewer features, but better speed. Flask is supported on v6+ platforms using Passagier.

Schnellstart

Alle Schritte werden vom Terminal. While it may be possible to deploy a Flask application without using terminal, it is strongly recommended for ease.

  1. Prerequisite: create a Beifahrer-kompatibel Dateisystem-Layout
  2. Change directories to the base, we’ll name the base directory flask in /var/www
    • cd /var/www/flask
  3. Optional: determine which Python version to use for Flask using pyenv
  4. Install flask using pip:
    • pip install flask
  5. Create a Passenger startup file to run Flask as a Python WSGI application:
    • from flask import Flask
      application = Flask(__name__)
       
      @application.route("/")
      def hello():
       return "Hello World!"
      
      if __name__ == "__main__":
       application.run()
    • Of importance, this example is identical to the Flask “Hello World!” example with a minor change: app is renamed to application to comply with Passenger. Passenger will always look for an instance variable named application to run the application.
  6. Verbinden Sie öffentlich/ to a subdomain within the control panel under Web > Subdomains
  7. Access your subdomain running Flask

Restarting a Flask app

Since Flask runs using Passenger, it uses the same restart method as any Passenger-backed app.

Siehe auch

 

Aktualisiert am März 7, 2021

Verwandte Artikel