• Stars
    star
    447
  • Rank 97,700 (Top 2 %)
  • Language
    CSS
  • Created about 13 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An easy-to-use Flask template for Heroku.

Flask Heroku




             ##
 #########  ###
  ##     #   ##                     :GG   DG
  ##         ##                     :EE   EE                        ;E
  ##         ##                     :EE  KK                         ;E
  ##         ##                     :EE                             ;E
  ##   #     ##     ####     ####   :EEEEEEG   KEEEE     WE  WEEE;  ;E   EE EE   EE  
  ######     ##    ##  #f   #   #   :EE   EE  GEf;tEK  EEKK EEfiEE, ;E  fE  EE   EE  
  ##   #     ##        #l   ##            EE  KE   tE  EK   E;   EE ;E  E,  EE   EE  
  ##         ##       ##a    ###          EK  EEEEEEE  EK   E    KE ;EEEE   EE   EE  
  ##         ##    ##  #s     ###         EK  EE       EK   E    KE ;E EE   EE   EE  
  ##         ##   ##   #k       ##   E    EE  EE       EK   E,   EK ;E  KE  EE   EE  
  ##         ##   ##   ##W  #   #:   E    EK  ;EK.,EK  EK   EE,:EE, ;E   ED KE.,EEE  
 #####      #####  ### W#   ####,         EK   ,KEEE   K#    DEEK.  iK   WK  KEEE.   


                    github.com/zachwill/flask_heroku

What is this?

A template to get your Flask app running on Heroku as fast as possible. For added convenience, the templates use Twitter's Bootstrap project to help reduce the amount of time it's takes you as a developer to go from an idea to a working site.

All of the CSS stylesheets are written using the Less CSS syntax (even Bootstrap's CSS). If you're using Mac OS X for development, make sure to check out incident57's Less.app.

Alternatively, there's a Less binary compiler that works similarly on the commandline, or you can always use the less.js script in your website otherwise -- it's incredibly fast. For instance, if you visit the Less CSS site, notice that it doesn't link to any CSS files.

Lastly, in Heroku's production environment, your Flask application will be served through gunicorn and gevent.

Why should I use this?

Everything I've learned from writing and maintaining the Flask Engine template for Google App Engine has made its way into this repo, too. The goal is to make a simple repo that can be cloned and added to for the majority of projects going forward, while also staying minimal in size and complexity.

Instructions

First, you'll need to clone the repo.

$ git clone [email protected]:zachwill/flask_heroku.git
$ cd flask_heroku

Second, let's download pip, virtualenv, foreman, and the heroku Ruby gem.

$ sudo easy_install pip
$ sudo pip install virtualenv
$ sudo gem install foreman heroku

Now, you can setup an isolated environment with virtualenv.

$ virtualenv --no-site-packages env
$ source env/bin/activate

Installing Packages

Gevent

To use gevent, we'll need to install libevent for the gevent production server. If you're operating on a Linux OS, you can apt-get install libevent-dev. If you're using Mac OS X, consider installing the homebrew package manager, and run the following command:

$ brew install libevent

If you're using Mac OS X, you can also install libevent through a DMG available on Rudix.

Without Gevent

If you'd rather use gunicorn without gevent, you just need to edit the Procfile and requirements.txt.

First, edit the Procfile to look the following:

web: gunicorn -w 4 -b "0.0.0.0:$PORT" app:app

Second, remove gevent from the requirements.txt file.

pip

Then, let's get the requirements installed in your isolated test environment.

$ pip install -r requirements.txt

Running Your Application

Now, you can run the application locally.

$ foreman start

You can also specify what port you'd prefer to use.

$ foreman start -p 5555

Deploying

If you haven't signed up for Heroku, go ahead and do that. You should then be able to add your SSH key to Heroku, and also heroku login from the commandline.

Now, to upload your application, you'll first need to do the following -- and obviously change app_name to the name of your application:

$ heroku create app_name -s cedar

And, then you can push your application up to Heroku.

$ git push heroku master
$ heroku scale web=1

Finally, we can make sure the application is up and running.

$ heroku ps

Now, we can view the application in our web browser.

$ heroku open

And, to deactivate virtualenv (once you've finished coding), you simply run the following command:

$ deactivate

Next Steps

After you've got your application up and running, there a couple next steps you should consider following.

  1. Create a new README.md file.
  2. Add your Google Analytics ID to the base.html template.
  3. Adjust the author and description <meta> tags in the base.html template.
  4. Change the humans.txt and favicon.ico files in the static directory.
  5. Change the apple-touch icons in the static directory.

Reactivating the Virtual Environment

If you haven't worked with virtualenv before, you'll need to reactivate the environment everytime you close or reload your terminal.

$ source env/bin/activate

If you don't reactivate the environment, then you'll probably receive a screen full of errors when trying to run the application locally.

Adding Requirements

In the course of creating your application, you may find yourself installing various Python modules with pip -- in which case you'll need to update the requirements.txt file. One way that this can be done is with pip freeze.

$ pip freeze > requirements.txt

Custom Domains

If your account is verified -- and your credit card is on file -- you can also easily add a custom domain to your application.

$ heroku addons:add custom_domains
$ heroku domains:add www.mydomainname.com

You can add a naked domain name, too.

$ heroku domains:add mydomainname.com

Lastly, add the following A records to your DNS management tool.

75.101.163.44
75.101.145.87
174.129.212.2

More Repositories

1

moment

A Python library for dealing with dates
Python
724
star
2

dom

Check domain name availability from the command line.
Python
214
star
3

flask-engine

A Flask skeleton for Google App Engine, using html5 boilerplate templating.
Python
177
star
4

fred

Python wrapper for the St. Louis Fed's FRED API.
Python
161
star
5

cracking-the-coding-interview

Python solutions for the book Cracking the Coding Interview
Python
124
star
6

asciifi

Turn your pictures into ASCII art
JavaScript
98
star
7

rottentomatoes

Rotten Tomatoes API for Python
Python
87
star
8

excssive

A drag and drop CSS compressor
JavaScript
58
star
9

markdrop

Drag and drop Markdown previews
JavaScript
48
star
10

pjax_flask

Testing out Flask with PJAX
JavaScript
43
star
11

hn

An easy-to-use CLI for HNSearch's API.
Python
31
star
12

ESPN-Basketball

An outdated ESPN Play-By-Play scraper... Not worth your time. Make your own!
Python
29
star
13

golf

Python
28
star
14

heroku_static

Serve all the things!
HTML
26
star
15

dotfiles

Command line goodness
Shell
19
star
16

cookiecutter-scrapy

A simple cookiecutter template for Scrapy projects
Python
18
star
17

dribbble

A simple Python wrapper for the Dribbble API
Python
10
star
18

mapq

An easy-to-use wrapper for the Mapquest Geocoding API.
Python
10
star
19

tumblr

An API wrapper for working with Tumblr and Tumblr's OAuth
Python
9
star
20

drinkups

Objective-C
9
star
21

beautiful_maps

A page-based iOS app highlighting some of Stamen's awesome maps.
Objective-C
8
star
22

darksky

A simple Python wrapper for the Dark Sky API
Python
7
star
23

blog

Current website.
JavaScript
7
star
24

usps_zipcodes

Scrape ZIP Codes from the USPS for a given city and state list.
Python
6
star
25

relaxml

Converting XML should be easy -- and fast.
Python
5
star
26

leetcode

Scraping Leetcode's GraphQL endpoint with Scrapy
Python
5
star
27

flask_cloud

A Flask template to get up and running with DotCloud.
JavaScript
5
star
28

github.vim

Github color scheme for iTerm vim
Vim Script
5
star
29

mcmc

Kruschke "Doing Bayesian Data Analysis" and Gelman/Hill "ARM" in PyMC3
Jupyter Notebook
4
star
30

covid-19

My simple COVID-19 death-to-recovery rate model
Jupyter Notebook
4
star
31

smsified

Sending SMS messages should be dead simple.
Python
4
star
32

playing-with-pulp

Playing around with PuLP in Python
Jupyter Notebook
4
star
33

zappa_template

An easy-to-use template for Zappa and CoffeeScript on Heroku
JavaScript
4
star
34

old

My personal website.
JavaScript
4
star
35

abhi_ipsum

Lorem ipsum with some panache
JavaScript
4
star
36

xml2dict

Fork of xml2dict project
Python
4
star
37

espn_ncaab

CoffeeScript
3
star
38

bittorrent-challenge

Python solution to the BitTorrent Developer Challenge
Python
3
star
39

random

CoffeeScript
3
star
40

bootmaker

Automated Bootstrap workflow
2
star
41

sinatra_template

A simple Sinatra template
JavaScript
2
star
42

background_color

A small app to help learn Backbone.js
JavaScript
2
star
43

madewithdata

Concept site for exploring data APIs.
JavaScript
2
star
44

stamen_maps

A simple UIWebView used to grab screenshots of Stamen's maps.
Objective-C
2
star
45

amazon-reviewers

Find profiles of reviewers who gave the same rating for a product.
Python
2
star
46

import_screencast

JavaScript
2
star
47

applescripts

Simple AppleScript examples.
2
star
48

import_zach

Because the name was available on PyPI.
Python
2
star
49

rebus_generator

ITA's Rebus Generator Puzzle
Python
2
star
50

abhi.info

Because the domain was available
JavaScript
1
star
51

practical_c

Solutions to exercises in the Practical C book.
C
1
star
52

img64

A service to base64 encode external image links
JavaScript
1
star
53

status

Objective-C
1
star
54

heroku_relaxml

A gut server that makes dealing with XML a whole lot easier.
JavaScript
1
star
55

popcorndoc.js

My fork of the popcorndoc.js plugin for Popcorn.js
JavaScript
1
star
56

domainsaurus

An easy-to-use mashup connecting Domainr's API with Wordnik's API
JavaScript
1
star
57

tatooine

A map of Tunisia with all marked Star Wars locations.
JavaScript
1
star
58

zippy

A simple wrapper for the Ziptastic ZIPCode API.
Python
1
star
59

word_dump

Python
1
star
60

xcode_textmate_theme

An XCode 4 color scheme from the theme I use in Vim and TextMate.
1
star
61

simplest

Working with Redis should be simple and Pythonic
Python
1
star
62

cookiecutter-streamlit

A quick cookiecutter template for creating Streamlit sites
Python
1
star
63

lr

JavaScript
1
star
64

wadsworth_constant

A Python script that returns the Wadsworth Constant for input
Python
1
star
65

holy_catchphrase

Catchphrases and action words from the Adam West Batman show
JavaScript
1
star
66

epa_pcs_zip_codes

EPA permits to pollute public water sources by ZIP Code.
Python
1
star
67

boardgames

Find new boardgames to play
Jupyter Notebook
1
star
68

backbone_zombie_test

A simple Backbone.js testing example using Vows and Zombie.js
CoffeeScript
1
star
69

bootstrap_tutorials

Quick Bootstrap tutorials
JavaScript
1
star