Django with Passenger

From Glitchdata
Jump to navigation Jump to search

Steps

  • Setup environment var PYTHONHOME
  • Setup environment var PYTHONPATH
  • Setup environment var DJANGO_SETTINGS_MODULE
    • os.environ['DJANGO_SETTINGS_MODULE'] = "projectname.settings"
  • You will need access to django/bin/django-admin.py
  • Setup passenger_wsgi.py
    • What Passenger needs is an "application" object.
    • A Django application object is used when integrating Django.

Project Organisation

Python is highly-flexible. This is good. It is also the bane when attemping to organise apps/libraries in a coherent way. Reality is that anything goes even in Django. This makes Django more of a library than a framework. Heroku (a leading cloud provider) has suggested certain project layouts.

  • /mysite/
    • /mysite/__init__.py (facilitates packaging the site as library?)
    • /mysite/manage.py - REMOVE
    • /mysite/settings.py - REMOVE
    • /mysite/urls.py - REMOVE
      • /mysite/proj - GLOBAL APPS
        • /mysite/proj/__init__.py
        • /mysite/proj/gd2 (an app)
          • /mysite/proj/gd2/__init__.py
          • /mysite/proj/gd2/models.py
          • /mysite/proj/gd2/tests.py
          • /mysite/proj/gd2/views.py
      • /mysite/app - GLOBAL APPS
        • /mysite/app/__init__.py
        • /mysite/app/blog (an app)
          • /mysite/app/blog/__init__.py
          • /mysite/app/blog/models.py
          • /mysite/app/blog/tests.py
          • /mysite/app/blog/views.py
      • /mysite/lib
        • /mysite/lib/__init__.py
        • /mysite/lib/display (an common library)
          • /mysite/lib/display/__init__.py
          • /mysite/lib/display/models.py
          • /mysite/lib/display/tests.py
          • /mysite/lib/display/views.py
    • /mysite/public
    • /mysite/passenger_wsgi.py
    • /mysite/requirements/prod.txt - using pip for installing dependencies.
    • /mysite/env/ (for custom python env)
      • /mysite/env/bin/python

Differences with WSGI

There is little difference with Django with WSGI. These are primarily:

  • a /public directory
  • The hook is passenger_wsgi.py instead of wsgi.py

Links

Alternatives