Most of the time, deployment sucks. Using a continuous integration app can help automate your deployments so you can focus on writing code and buildings things. In this post I’ll show you how to set up a basic Django project with CircleCI so that publishing your code is as simple as pushing to GitHub.
As of Django 1.9, there are a number of new permission mixins you can use with your views to make access control easier. One that isn’t included by default is a mixin allowing you to only permit users who have activated their account (
user.is_active = True)
- Save yourself writing the same queries time and time again by creating a simple model manager with common queries for your generic foreign keys
This post outlines a simple Django app that allows the user to upload an image via an URL while making sure the image file is valid.
One of my most popular Stackoverflow answers is to a question regarding the confusion between static and media files in Django. This post elaborates on that theme.
In a previous post I outlined a sane folder structure for a new Django project. Since then Django 1.5 (and 1.6) has been released along with an updated default folder structure. This post goes through some further tips on keeping your django project layout sensible.
- A very nice and clean way to deploy a Jekyll (or any other static generated site) is to setup a very small application on your sites webserver to listen for post commit hooks from Bitbucket. This allows you to have your site automatically updated and regenerated every time you push to your repository. This post shows you how.
I was recently getting this error while trying to deploy a new project to production. It turns out that due to a recent security update, you need to make sure that the incoming host name in your request is valid.
Sorl-thumbnail has a sensible crop function in the default engine, but sometimes you need a little more control over the results. This post provides a custom cropping PIL engine that can be used to return specific, i.e. from (x1, y1) to (x2, y2), cropped thumbnails
If you update
request.GETin a view (or else where), any subsequent calls to
request.REQUESTwill still return values from the old, outdated
It’s very easy to generate URLs to your django models using
get_absolute_url(), but you can also use this pattern to just as easily create URLs to the admin page for your django models too. This post shows you how to make a
get_admin_url()model method that generates links to give you quick access to your admin.
GenericRelationswith Django to create unique generic foreign keys between objects, it can become tiresome having to navigate the
RelatedManagerevery time you need to retrieve the single instance of the one-to-one relationship. This post shows how creating a quick ‘Mixin‘ can help overcome this inconvenience.
Django’s annotate method can be useful for counting particular attributes on every member of a queryset (i.e. count the number of books an author has). Unfortunately you can’t use the ORM to do any filtering on those attribute. This would be useful for only considering an attribute if it were above a certain value, or belonged to a certain object (i.e. count the number of books with the tag ‘Horror’). This post shows how to make use of the ‘extra‘ method Django provides to create filtered annotations
Fandjango is a great application for getting a Facebook Canvas application up and running. It provides a nice view decorator to ensure a user is authorised with Facebook before allowing them access to that view. This post provides a piece of middleware that makes use of that decorator, allowing you to enforce Facebook authorisation on *all* views in your application.
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
At times you need to use both
easy_thumbnailsin the same template. Both of these apps define a
thumbnailtemplate tag from a
thumbnailtemplate 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 called
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.
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.