A General Django Project Structure or Folder Layout
When beginning with Django I always found it difficult to decide on basic project layouts. What should go where and why? Having read many of the great articles on the topic already out there this post outlines how I have come to manage the folder structure of most of my new Django projects, making sure everything is tidy and safe
Don't keep sensitive information in your Django settings
If you are checking your settings.py into Git, make sure you aren’t including any potentially sensitive information such as database passwords, secret keys and so on. A quick and easy way to avoid this is to create a separate ‘sensitive.py‘ file.
Create automatic redirects upon changing an URL dependent field in your Django Models
When the generated URLs of your objects depends on a field in your model that could potentially change (for example a slug field that is generated from a title which your editor just changed), you can get yourself into trouble with Google as your old URL will now return a 404. This posts outlines an approach to dynamically create redirects whenever an objects changes an url dependant field.
Misconceptions with "select_related" in Django
Django’s
select_related
QuerySet method is a great way to reduce the query count when joining tables but it should come with small print in the documentation. This post goes over that small print.Using sorl thumbnail and easy thumbnails in the same template
At times you need to use both
sorl.thumbnail
andeasy_thumbnails
in the same template. Both of these apps define athumbnail
template tag from athumbnail
template module meaning that you will be able to use one or the other but not both. To get around this, you can install a great app calleddjango-smart-load-tag
Using a virtualenv with CodeRunner.app
I’m a big fan of using Virtualenv (and virtualenvwrapper) where possible. It allows you to cleanly manage multiple Python environments. I also occasionally use CodeRunner to test, debug and run standalone scripts. It wasn’t immediately clear to me how to make CodeRunner run inside one of my virtualenvs so this post gives a quick outline on how to get the two to work nicely together.Django CMS Urls not reversing properly
I encountered a strange problem when making use of a custom AppHook with django-cms. When I mounted a custom app on a cms page, reversing the urls in the template for that app (using get_absolute_url) was producing incorrect urls.