Managing
Django
Requirements

PROTIP #1:
Use virtualenv and virtualenvwrapper

PROTIP #2:
Install you packages using pip

Some basic pip commands...

 
Install a package   pip install Django
Install a specific version   pip install Django==1.5.2
Update a package   pip install -U Django
Freeze your environment
  pip freeze
to a file   > requirements.txt
Install your environment
  pip install -r
    requirements.txt

PROTIP #3: 
Freeze!

Requirements belong in requirements files

requirements.txt

  Django==1.4.5
 Markdown==2.2.0
 dj-database-url==0.2.1
 django-taggit==0.9.3
 html2text==3.200.3
 icalendar==3.1
 psycopg2==2.4.5 
 pytz==2012d
 wsgiref==0.1.2

Basic Django Project Layout


project/
apps/
manage.py
requirements.txt

Ideal Django Project Layout


project/
apps/
manage.py
requirements/
_base.txt
development.txt
production.txt
staging.txt
requirements.txt

Why is it better?

  • Separates development and production requirements
  • Faster environment installation
  • Every requirement has it's place
  • Easier to manage and keep up to date

_base.txt

   Django==1.5.2  Pillow==2.0.0  South==0.8.1  requests==1.2.3  pytz==2013b

development.txt

   # Import Base Requirements  -r _base.txt    # Development Specific Requirements  django-debug-toolbar==0.9.4  django-devserver==0.6.2  ipython==0.13.2  Fabric==1.6.1

production.txt

   # Import Base Requirements  -r _base.txt
# Production Requirements gunicorn==0.14.6
uWSGI==1.9.2
# PostgreSQL psycopg2==2.5 

requirements.txt

   # Because we want to deploy to Heroku  -r requirements/production.txt

PROTIP #4:
Keep Your Requirements
Up To Date!

Watch for releases of packages you use

Mailing lists

https://crate.io


pip-tools

https://github.com/nvie/pip-tools


piprot

https://github.com/sesh/piprot