Configuring your first django project

26 February, 2016
Python Django

Whenever i build any application with django, and create a boilerplate project. There are some changes in overall project settings and structure that i always end up doing. Creation of static and template folder for your project and the corresponding settings .

Suppose your project name is xyz, In your project root path, where your resides. Add two folder named static and templates. This is where you can put your static like css/js/icons etc and templates for your templates (HTML file)

Once this is done, django needs to be told what these folder are for. To do this, add the following lines to your When you are learning and creating your first project. This is something that i feel is missing.

    os.path.join(BASE_DIR, 'xyz/static'),
    os.path.join(BASE_DIR, 'xyz/templates'),

When in production or running behind a project. Don't make django serve your static files. Configure STATIC_ROOT where django collects all your static files at one place. You can use nginx to server your static files with some configurations

For local development you can use DEBUG=True which tells django to serve static files as well. You can add a settings like this

if not DEBUG:
    STATIC_ROOT = 'path_to_static_folder'

Now when your python collectstatic. All your files are collected into the static folder mentioned in STATIC_ROOT

Thank you for taking the time to read this post. If you're considering using Digital Ocean, the hosting provider this blog is hosted on, please consider using this link to sign up.