public
Last active

  • Download Gist
flask_development_env.md
Markdown

Create a Basic Flask Development Environment

This tutorial walks you through setting up the tools you need to begin developing in Python and Flask. Note: I assume you are on a Unix environment (OSX, Linux, Linux VM on Windows).

What you need

  • Python 2.7.x
  • easy_install and pip
  • Git 1.7/1.8
  • virtualenv
  • Flask
  • Text editor (Sublime, vim, Komodo, gedit)

Python

  1. Check your Python version - python -V
  2. If you already have a 2.7.x version, move on to the next step.
  3. If not, download and install the latest 2.7.x version

Git

  1. Check your Git version - git --version
  2. Download the latest version, if necessary

easy_install and pip

  1. Download setuptools for Python 2.7

    $ curl -o setuptools-0.6c11-py2.7.egg https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
    
  2. Install setup tools

    $ sudo sh setuptools-0.6c11-py2.7.egg
    
  3. Clean up and delete egg

    $ rm setuptools-0.6c11-py2.7.egg
    
  4. Install pip

    $ sudo easy_install pip
    

virtualenv

virtualenv is used to create a self-contained development environment.

  1. Install

    $ sudo pip install virtualenv
    
  2. Setup your local environment

    $ mkdir new_project
    $ cd new_project
    $ virtualenv --no-site-packages flask
    
  3. Activate virtualenv

    $ cd flask
    $ source bin/activate
    

Flask

  1. Install

    pip install Flask
    

Version Control

  1. Add a Git repository

    $ git init
    

Text editor

  1. Download a text editor. I prefer Sublime.

Quick Application

  1. Create a new file named hello.py and add the following code:

    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
        return 'Hello World!'
    
    if __name__ == '__main__':
        app.run()
    

    Save the file to your "flask" directory.

  2. Run the file with your Python interpreter

    $ python hello.py
    
  3. Point your browser at http://localhost:5000 to view the hello world greeting.

Congrats! Flask has taken the main stage. Cheers.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.