I have discussed in a previous post how my server was organized. I will discuss now how my Django web pages are organized.
When I started Django, I realized that one of the power of this framework was it’s flexibility. You could put your site on-line in 1000 different ways. But this flexibility (and lack of a standard or preferred solution, by the way) was also one of the major drawbacks for me. I spend quite a lot of time experimenting with different solutions, and arrived eventually to a suitable schema.
My machine serves 3 web sites at the moment (2 blogs and one community web site), all of them completely under Django. Those need bug corrections and other improvements on a regular basis, as well as the applications that they run. And those improvements should be deployed as easily as possible.
For deployment I use svn. I go to the folder where I keep all my code, I type svn up * and everything gets up-to-date. The svn servers are hosted separately from the web server.
I have a common directory for sites and applications, /www/. Here, each application and web page has a folder. For instance, guindilla and www_guindilla_eu have their own folders.
The applications are self-descriptive. I tend to have a generic library name (guindilla in my case, or the name of my client or company) and specific names of the applications. Guindilla has the blog app, the polls app and many others. Those apps are as self-dependent as possible, thus enabling an easy use in any web page.
My sites are in self-contained folders. In those folders you find:
- settings.py and urls.py specific to the given site.
- A database with name site_name.db
- feeds.py, as the feeds are specific to each site.
- media folder.
- templates folder.
The settings.py and uls.py are easy enough to understand, as is the templates folder. The media folder is a bit more tricky.
The media folder contains the following folders:
- css where all css related files are stored. I try to store the css files specific to a site in a folder of the same name. Thus, the css of this site is stored in www_guindilla_eu/media/css/www_guindilla_eu/.
- img where all image files are stored. The situation is the same as before, with images stored in www_guindilla_eu/media/img/www_guindilla_eu/.
- js for widely used javascript code.
- app_name1
- app_name2
The first question might be, why the css and images of a same site are under a common directory? In my deployment each site has it’s own media folder. But sometime I might want to have a common media folder for all sites. In this situation, the transition will be easy to do, as each site image and css is in it’s own ‘space name’, and will not conflict one with each other.
The second question is, why a folder for applications? Sometimes applications need to store files or other documents, and we don’t want them to get mixed up. So this way each file is well organized in an easy to identify folder.
I will end up listing, as an example, a listing of all files of this site folder as a practical example:
__init__.py feeds.py manage.py media/css/lightbox.css media/css/www_guindilla_eu/style.css media/guindilla/blog/ media/guindilla/tags/ media/img/stockphoto/blank.gif media/img/stockphoto/close.gif media/img/stockphoto/closelabel.gif media/img/stockphoto/loading.gif media/img/stockphoto/next.gif media/img/stockphoto/nextlabel.gif media/img/stockphoto/prev.gif media/img/stockphoto/prevlabel.gif media/img/www_guindilla_eu/apache_pb.gif media/img/www_guindilla_eu/bullet.gif media/img/www_guindilla_eu/djangosite80x15_grey.gif media/img/www_guindilla_eu/leftheader.jpg media/img/www_guindilla_eu/navbarhover.gif media/img/www_guindilla_eu/navbutton.gif media/img/www_guindilla_eu/python.png media/img/www_guindilla_eu/rightheader.jpg media/img/www_guindilla_eu/rss.png media/js/effects.js media/js/lightbox.js media/js/prototype.js media/js/scriptaculous.js media/stockphoto/ settings.py templates/404.html templates/500.html templates/base.html templates/base_site.html templates/comments/freeform.html templates/comments/free_preview.html templates/comments/posted.html templates/guindilla/about_me.html templates/guindilla/blog/base_blog.html templates/guindilla/blog/friends.html templates/guindilla/blog/post.html templates/guindilla/blog/post_archive.html templates/guindilla/blog/post_archive_day.html templates/guindilla/blog/post_archive_month.html templates/guindilla/blog/post_archive_year.html templates/guindilla/blog/post_detail.html templates/guindilla/blog/post_search_results.html templates/guindilla/extras.html templates/guindilla/ips/base_ips.html templates/guindilla/ips/ips_ipaddresses.html templates/guindilla/ips/ips_results.html templates/guindilla/ips/ips_visits.html templates/guindilla/links/link_detail.html templates/guindilla/links/link_list.html templates/guindilla/login.html templates/guindilla/menu.html templates/guindilla/polls/open_polls.html templates/guindilla/polls/poll_detail.html templates/guindilla/polls/poll_list.html templates/guindilla/polls/poll_results.html templates/guindilla/rss.html templates/guindilla/search.html templates/guindilla/tags/all_tags.html templates/guindilla/tags/tag_detail.html templates/guindilla/tags/tag_list.html templates/guindilla/tasks/detailed_task.html templates/guindilla/tasks/simple_task.html templates/guindilla/tasks/task_detail.html templates/guindilla/tasks/task_list.html templates/index.html templates/registration/logged_out.html templates/registration/login.html templates/stockphoto/gallery_detail.html templates/stockphoto/gallery_list.html templates/stockphoto/import_form.html urls.py www_guindilla_eu.db

Entries
elake
on Nov 16th, 2006
@ 15:46:
Will you make the code used to create the site available so that others can learn from what you have created?
Guille
on Nov 17th, 2006
@ 00:58:
It is already available
The code is on my svn:
http://svn.guindilla.eu:8000/
It’s a bit messy, and a mix of several projects. You can find:
- guindilla: The code of the blogs http://www.guindilla.eu and http://www.haruki.eu. guindilla itself is divided into modules that can work together or be used independently (blog, polls, events, links,…).
- www_guindilla_eu and www_haruki_eu: The templates of the two blogs mentioned above
- complutense: The code of a site that allows students of one master of the complutense (http://www.ucm.es) to share mp3 and files, as well as the first draft of my events framework (please, use the one in guindilla/events/ !!).
- complu_haruki_eu: The templates of the above site.
- stockphoto: The modified code of the excellent stockphoto image gallery you can find at http://www.carcosa.net/jason/software/django/stockphoto/
Hope it helps!