Showing posts with label configuration. Show all posts
Showing posts with label configuration. Show all posts

Friday, December 5, 2014

Django default settings

From appendix D of the djangobook:

Default Settings

A Django settings file doesn’t have to define any settings if it doesn’t need to. Each setting has a sensible default value. These defaults live in the file django/conf/global_settings.py.
Here’s the algorithm Django uses in compiling settings:
  • Load settings from global_settings.py.
  • Load settings from the specified settings file, overriding the global settings as necessary.
Note that a settings file should not import from global_settings, because that’s redundant.

Tuesday, November 25, 2014

Configuring nginx to serve static files in django

The setup that I use right now relies on Nginx to handle static files and goes to Gunicorn when there's a need to interface with Python.

I update the files on the server by using 'git push live master,' where 'live' is the name of a repository on the server that has hooks set to update a directory that lives in Django.  That directory includes the static files (css, js) that my pages rely on. 

It is possible to configure Django to automatically copy all static files to a single location. Then all you need to do make sure that that location is the one that your nginx configuration points at.  See the docs here.

In my case, I keep all my static files gathered under a directory named "static" so I just pointed Nginx at that directory.  It's reasonably likely that I'll need to change that pointer at some point, so I'm writing a reminder of what I had to do right here.


First I found the relevant configuration file for nginx.  On my Ubuntu VPS that file was under

/etc/nginx/sites-available/username


where 'username' was the user that I was set up under.  There is also a default configuration file, which would be used in the absence of the more specific username configuration. 

Second, in that file I altered the following address to point directly to my static directory

     location /static {
        alias /home/path/to/my/static/directory;
    }




Third, I refreshed nginx:
sudo nginx -reload


Fourth: There was no fourth step.  That's it!