Init First Documetation
This commit is contained in:
47
HowToStart/1_3_helloworld_flask.md
Normal file
47
HowToStart/1_3_helloworld_flask.md
Normal file
@@ -0,0 +1,47 @@
|
||||
title: 1.3 Hello World mit Flask
|
||||
Erstelle eine kleine Python Datei, zB test.py mit dem Inhalt:
|
||||
|
||||
:::python
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello_world():
|
||||
return 'Hello, World!'
|
||||
|
||||
Starte den Development Server mit
|
||||
|
||||
:::bash
|
||||
FLASK_APP=test.py flask run --host=0.0.0.0 --port=8104
|
||||
Ändere den Port und den Dateinamen entsprechend.
|
||||
Damit das jeweilige Startcommando nicht jedesmal eingetippt werden muss, empfehle ich eine run Datei zu erstellen:
|
||||
|
||||
run
|
||||
|
||||
:::bash
|
||||
#!/bin/bash
|
||||
. .env/bin/activate # Die Pythonumgebung laden
|
||||
#
|
||||
# Starten des flask Development Sers
|
||||
# Die App muss in einer Datei sein,
|
||||
# host 0.0.0.0 bedeutet, dass der Developmentserver auch von anderen erreicht werden kann.
|
||||
# Default wäre dass der Server am Entwickulungsrechner lokal betrieben wird
|
||||
# Port bitte auf den jeweiligen Wert ändren
|
||||
FLASK_APP=test.py flask run --host=0.0.0.0 --port=8104
|
||||
|
||||
jetzt ein Terminal öffnen und die Datei lauffähig machen
|
||||
|
||||
:::bash
|
||||
chmod +x run # Ausführen erlauben
|
||||
./run # Ausführen
|
||||
|
||||
|
||||
Im Terminal sollte jetzt etwa folgende Ausgabe erscheinen
|
||||
|
||||
:::bash
|
||||
* Serving Flask app "test.py"
|
||||
* Environment: production
|
||||
WARNING: This is a development server. Do not use it in a production deployment.
|
||||
Use a production WSGI server instead.
|
||||
* Debug mode: off
|
||||
* Running on http://0.0.0.0:8104/ (Press CTRL+C to quit)
|
||||
Reference in New Issue
Block a user