django using template and static files (css, images, javascript)
2013-01-22
Please note: this is a note from my early experience of django and the method demonstrated here is not quite beautiful, especially you got several applications under the same project. Check out my new note.
=============================================================================================
So for the template, you need to edit TEMPLATE_URL in the settings.py
For css/javascript, django regards these as static files, make a static folder under the main folder, and use that to store your css/javascript files.
Before you can use them, you need to edit STATIC_URL and MEDIA_URL in the settings.py, such as
STATIC_URL = '/static/'
Last step is to serve it when request comes, it is apache's job. Put the following two lines in apache website config file:
Alias /media/ PROJECT_PATH/media/
Alias /static/ PROJECT_PATH/static/
Then you can reference these static files in your template in this way:
<link rel="stylesheet" href="/static/css/style.css" type="text/css" />
<script type="text/javascript" src="/static/js/libs/jquery.min.js"></script>