Git Product home page Git Product logo

django-skeleton's Introduction

django-skeleton

A Sample Django application that illustrates what bits make up a sane Django based web app deployment.

$ virtualenv ve
$ source ve/bin/activate
(ve)$ pip install -r requirements.pip

You can use Git to merge this repository into your own code if you would like to use it as a starting point:

$ git remote add skeleton https://github.com/praekelt/django-skeleton.git
$ git fetch skeleton
$ git merge skeleton/develop

South

South manages your schema and data migrations well enough. As part of a deploy we expect any schema changes needed to be part of your repository and handled by south.

For your initial schema:

(ve)$ ./manage.py schemamigration --initial <app-name>

For subsequent schema changes:

(ve)$ ./manage.py schemamigration --auto <app-name>

The schema changes can be applied manually with:

(ve)$ ./manage.py migrate

Or generally what happens as part of a deploy is:

(ve)$ ./manage.py syncdb --noinput --no-initial-data --migrate

As an example, the sample app1 application's migrations were created with the following commands after creating the app1/models.py file:

(ve)$ ./manage.py schemamigration --initial app1
Creating migrations directory at '.../django-skeleton/app1/migrations'...
Creating __init__.py in '.../app1/migrations'...
 + Added model app1.App1Model
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate app1

A later change to the model definition is detected by South and a new schema migration is generated to reflect this change:

(ve)$ ./manage.py schemamigration --auto app1
 + Added field gender on app1.App1Model
Created 0002_auto__add_field_app1model_gender.py.
You can now apply this migration with: ./manage.py migrate app1

Supervisord

Supervisord manages your processes and allows us to ensure that your applications are a) running and b) come up at boot should the server be restarted for whatever reason.

The folder etc/ has supervisord.conf file that's read by supervisord. The application specific files are in etc/conf.d/*.conf.

For each process that needs to be run by your application ensure that the process is included in a .conf file:

(ve)$ supervisord
(ve)$ supervisorctl
celery                           RUNNING    pid 24069, uptime 0:35:04
django                           RUNNING    pid 24070, uptime 0:35:04
supervisor> restart celery
celery: stopped
celery: started
supervisor> tail -f celery
==> Press Ctrl-C to exit <==
[2013-06-18 21:41:28,571: WARNING/MainProcess] [email protected] ready.
[2013-06-18 21:41:28,576: INFO/MainProcess] consumer: Connected to redis://localhost:6379/0.
...

Celery

Anything that requires moderate to heavy lifting, which could cause a potentially slow response time, should be left for Celery to handle.

This includes sending emails, logging, database based cleanup tasks.

Celery allows you to define tasks that are scheduled from your Django views but which are run by the Celery worker running in the background, allowing your Django application to return the HTTP response to the user as soon as possible.

How to use Celery from Django is documented at celeryproject.org

This skeleton application uses Redis as the broker for Celery, in production this is going to be RabbitMQ.

A sample application called celery_app is part of this skeleton as an example. Visit http://localhost:8000/celery/ to see it in action if you've got supervisord running.

Gunicorn

Gunicorn is the application server we're using to servce our Django applications with. Generally this sits behind Nginx and HAProxy.

We are expecting your Django applications to be run with this, no exceptions.

Sentry

Sentry is a realtime error logging and aggregation platform. We have a dedicated installation for our Django based projects.

Raven is the client that submits the errors to Sentry. We will supply you with a key for you to configure your raven client with.

django-skeleton's People

Contributors

smn avatar calston avatar

Watchers

Avukonke Peter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.