Created
February 8, 2019 10:26
-
-
Save PsHegger/f0770cb67ff090c455911c6d3aad121d to your computer and use it in GitHub Desktop.
A simple script to create a basic Flask app
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
#!/usr/bin/env bash | |
echo "Creating project directory" | |
mkdir $1 | |
cd $1 | |
echo "Initializing virtual environment" | |
python3 -m venv venv | |
. venv/bin/activate | |
pip install Flask > pip.log | |
echo "Creating startup script" | |
cat >> run.sh << EOF | |
. venv/bin/activate | |
export FLASK_APP=app.py | |
export FLASK_ENV=development | |
flask run | |
deactivate | |
EOF | |
chmod +x run.sh | |
echo "Creating application" | |
cat >> app.py << EOF | |
from flask import Flask, render_template | |
import os | |
app = Flask(__name__) | |
if os.environ['FLASK_ENV'] == 'development': | |
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 | |
@app.route('/') | |
def index(): | |
return render_template('index.html', app_name="$1") | |
EOF | |
echo "Creating templates" | |
mkdir templates | |
cat >> templates/index.html << EOF | |
<!doctype html> | |
<html> | |
<head> | |
<title>Hello {{app_name}}</title> | |
<link rel="stylesheet" type="text/css" href="/static/style.css" /> | |
</head> | |
<body> | |
<div>Hello {{app_name}}</div> | |
</body> | |
</html> | |
EOF | |
echo "Creating static files" | |
mkdir static | |
cat >> static/style.css << EOF | |
div { | |
font-family: monospace; | |
} | |
EOF | |
deactivate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment