Python Development Guide¶
Python is a very powerful language that we use for many different projects at Teracy. In this guide, we’re going to explore the Python language and some Python web frameworks.
Python
should be available by default on the teracy-dev
VM, so make sure you have the
teracy-dev
VM running by following the Getting Started guide.
Note
pyenv, virtualenv and virtualenvwrapper are already installed and available to use.
Verify that Python
Works¶
$ vagrant ssh
$ python --version
And you should see something like this:
Python 2.7.6
Congratulations, you can do all Python
related stuff now!
Learn¶
There are many free resources for learning Python and those listed ones below are just some of those. We should learn from easy to harder levels.
Python tutorial
Introduction about Python: https://docs.python.org/2/tutorial/index.html
Python Course
Very easy to follow: http://www.codecademy.com/tracks/python
Dive into Python
Useful for middle level: http://www.diveintopython.net/toc/index.html
Learn Python the hard way
Required to work: http://learnpythonthehardway.org/book/
Flask Framework¶
After learning Python
, you should know how to use Flask for web application development.
Follow the steps below to get started.
Create a virtualenv
$ ws $ cd personal $ mkdir flask-app $ cd flask-app $ mkvirtualenv flask-app
Install the Flask package
$ pip install Flask
Create hello.py under flask-app directory with the following content:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(host='0.0.0.0')
Run the
Flask
web app$ python hello.py
Now open http://localhost:5000 on the browser to see the web app.
Tip
Teracy introduces flask-boilerplate to speed up Flask development with best practices.
Django Framework¶
After learning Python
, you should know how to use Django for web application development.
Follow the steps below to get started.
Create a virtualenv
$ ws $ cd personal $ mkvirtualenv django-app
Install the Django package
$ pip install Django
Create a Django application
$ django-admin startproject django_app
Run the Django application
$ cd django_app $ python manage.py migrate $ python manage.py runrver 0.0.0.0:8000
Now open http://localhost:8000 on your browser to see the web app.
Tip
Teracy introduces django-boilerplate to speed up Django development with best practices and we follow the Django Training guide.