Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created October 12, 2011 04:07
Show Gist options
  • Save matiskay/1280238 to your computer and use it in GitHub Desktop.
Save matiskay/1280238 to your computer and use it in GitHub Desktop.
Flask Scaffold
flask.sh
Creates a scaffold to work witht flask
app.py
env/
static/
└── js
│ ├── custom.js
│ ├── jquery.js
│ └── underscore.js
templates/
├── base.html
└── index.html
#! /bin/bash
# PRECONDITIONS
# virtualenv
# virtualenv -> http://flask.pocoo.org/docs/installation/#virtualenv
function makeapp() {
{
echo "from flask import Flask, render_template"
echo ""
echo "app = Flask(__name__)"
echo "app.debug = True"
echo ""
echo "@app.route('/')"
echo "def index():"
echo " return render_template('index.html')"
echo ""
echo "if __name__ == '__main__':"
echo " app.run()"
} > app.py
}
function makeindex() {
{
echo "{% extends 'base.html' %}"
echo "{% block title %}Welcome Aboard{% endblock %}"
echo "{% block content %}Welcome Aboard{% endblock %}"
} > index.html
}
function makebase() {
{
echo '<!DOCTYPE html>'
echo '<html>'
echo ' <head>'
echo ' <meta charset="UTF-8" />'
echo ' <title>{% block title %}{% endblock %}</title>'
echo " <link type=\"text/css\" rel=\"stylesheet\" href=\"{{ url_for('static', filename='css/style.css') }}\" />"
echo " <script type=\"text/javascript\" src=\"{{ url_for('static', filename='js/jquery.js') }}\"></script>"
echo " <script type=\"text/javascript\" src=\"{{ url_for('static', filename='js/underscore.js') }}\"></script>"
echo " <script type=\"text/javascript\" src=\"{{ url_for('static', filename='js/custom.js') }}\"></script>"
echo ' </head>'
echo ' <body>'
echo ' {% block content %}{% endblock %}'
echo ' </body>'
echo '</html>'
} > base.html
}
PROJECT_NAME=$1
BASE=${PWD}/${PROJECT_NAME}
if [[ ! -n $1 ]]; then
echo 'Please, provide the following parameters: project_name'
echo ''
echo 'For example: '
echo ''
echo " $ bash $0 project_name"
echo ""
exit 1
fi
mkdir $PROJECT_NAME || exit
cd $PROJECT_NAME
# Generate the virtualenv called env
virtualenv --no-site-packages env
# Activation the virtualenv
. env/bin/activate
# Install flask
pip install flask
# Generate app.py
makeapp
# Generate a static folder for static files
mkdir static
cd static || exit
mkdir js
cd js || exit
printf "Downloading %s \n" "jquery 1.6.1"
wget -q "http://code.jquery.com/jquery-1.6.1.js" -O jquery.js
wget -q "http://documentcloud.github.com/underscore/underscore.js" -O underscore.js
touch custom.js
# Generate a css folder
cd $BASE
mkdir css
cd css || exit
touch style.css
cd $BASE
# Generate a template folder for templates
mkdir templates
cd templates || exit
makeindex
makebase
echo "go to your directory : $PWD"
echo '. env/bin/activate'
echo 'Run python app.py'
echo 'Now flask is up and running'
echo 'Open a new terminal and start coding'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment