Setting up my own flavour of Django

Okay, so I started doing stuff in python and of course stated playing around with django. And beeing used to padrinorb‘s convenient generators, I had to figure out how to get to my preferred setup. This is what I do:

  1. Run

    django-admin.py startproject projectname

  2. in settings.py
    add

    import os.path
    and add

    os.path.join(os.path.dirname(__file__), ('templates'))
    to TEMPLATE_DIRS

  3. Make dir templates/ in the project folder
  4. Make dir views/ in the project folder
  5. Add an __init__.py file
  6. import your views in __init__ (e.g.

    from index import hello
    if you have a view file called index.py containing a function hello())

  7. In templates I put subdirs for all sites and a base.html which holds the frame for all sites.
  8. Now in urls.py import all views via

    from views import *

So, this gives me a view and a template dir as well as a frame for the sites.

Now that I got the views and template going I would like to have a seperate dir for static contents. Django’s static dir is simply /static whih is fine by me, but making a directory named static and putting stuff in won’t do. You have to put


STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__), 'static/'),)

After putting


{% load staticfiles %}

into the base.html. You can insert static files like css, image and so on by putting


{% static foo/bar.ext %}

into the template tag.

Advertisements