Skip to content

Instantly share code, notes, and snippets.

@mpobrien
Created December 7, 2011 04:07
Show Gist options
  • Save mpobrien/1441415 to your computer and use it in GitHub Desktop.
Save mpobrien/1441415 to your computer and use it in GitHub Desktop.
flask setup
#!/bin/sh
projectname=$1
mkdir $projectname
mkdir $projectname/$projectname
mkdir -p $projectname/$projectname/templates
mkdir -p $projectname/$projectname/static
echo "#!/usr/bin/env python
from $projectname import app
app.debug = True
if __name__ == '__main__':
app.run(port=5001,host='0.0.0.0')" > $projectname/runserver.py
chmod +x $projectname/runserver.py
echo "from $projectname import app
from flask import Flask
#from pymongo.objectid import Object
#from pymongo import Connection
#import json
#import redis
#from mongokit import Document
#r = redis.Redis(host='localhost',port=6379,db=0)
#connection = Connection('localhost', 27017)
#db = connection['$projectname']
#collection = db.collection
#class User(Document):
#structure = { 'email': unicode,
#'pw_hash':unicode,
#'confirmed':bool,
#'created_at': datetime.datetime,
#'token':unicode }
#@staticmethod
#def get_by_email(email):
#users = connection['$projectname'].users
#return users.User.find_one({"email":email})
#@staticmethod
#def register_new_user(email, password):
#users = connection['$projectname'].users
#newuser = users.User()
#newuser.email = unicode(email)
#newuser.set_password(password);
#newuser.confirmed = False;
#newuser.created_at = datetime.datetime.now()
#newuser.token = unicode(generateRandomToken(48));
#newuser.save();
#return newuser;
#def set_password(self,password):
#self.pw_hash = unicode(generate_password_hash(password))
#def check_password(self,password):
#return check_password_hash(self.pw_hash, unicode(password))
#use_dot_notation = True
#def __repr__(self):
#return '<User %r>' % (self.email)
" > $projectname/$projectname/models.py
secretkey=$(python -c "import os; print repr(os.urandom(24))")
echo "from flask import Flask
app = Flask(__name__)
#app.debug = True
app.secret_key = $secretkey
#MONGODB_HOST = 'localhost'
#MONGODB_PORT = 27017
app.config.from_object(__name__)
import $projectname.views
import $projectname.models
import $projectname.forms
" > $projectname/$projectname/__init__.py
echo "from wtforms import Form, BooleanField, TextField, PasswordField, HiddenField
from wtforms.widgets import TextArea
from wtforms import validators
class LoginForm(Form):
email = TextField('Email', [validators.Required()])
password = PasswordField('Password', [validators.Required()])
class RegisterForm(Form):
name = TextField('Developer', [validators.Required()])
email = TextField('Email', [validators.Required(), validators.Email()])
password = PasswordField('Password', [validators.Required(),
validators.Length(min=6, max=64,message='Password must be at least 6 characters.'),
validators.EqualTo('confirm', message='Passwords must match.')])
confirm = PasswordField('Confirm Password')" > $projectname/$projectname/forms.py
echo "from $projectname import app
from flask import Flask
from flask import render_template, request, jsonify, g, redirect, url_for, session, abort, flash
import re, os, sys, json
@app.route(\"/\")
def home():
return render_template(\"index.html\", message=\"hello\")" > $projectname/$projectname/views.py
echo '<html>
<head>
<link rel="stylesheet/less" type="text/css" href="/static/styles.less">
<script src="/static/less.min.js" type="text/javascript"></script>
</head>
<body>
<div>{{message}}</div>
</body>
</html>' > $projectname/$projectname/templates/index.html
echo '' > $projectname/$projectname/static/styles.less
echo "fetching jquery"
curl -s "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" > $projectname/$projectname/static/jquery.min.js
curl -s "http://lesscss.googlecode.com/files/less-1.1.3.min.js" > $projectname/$projectname/static/less.min.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" > $projectname/$projectname/static/bootstrap.min.css
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" > $projectname/$projectname/static/bootstrap.min.css
curl -s "" > $projectname/$projectname/static/bootstrap.min.css
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-modal.js" > $projectname/$projectname/static/bootstrap-modal.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-alerts.js" > $projectname/$projectname/static/bootstrap-alerts.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-dropdown.js" > $projectname/$projectname/static/bootstrap-dropdown.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-scrollspy.js" > $projectname/$projectname/static/bootstrap-scrollspy.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-tabs.js" > $projectname/$projectname/static/bootstrap-tabs.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-twipsy.js" > $projectname/$projectname/static/bootstrap-twipsy.js
curl -s "http://twitter.github.com/bootstrap/1.3.0/bootstrap-popover.js" > $projectname/$projectname/static/bootstrap-popover.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment