Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
any2any - flexible serialization / deserialization for Python and Django
Why on earth ? When doing web programming, we all the time have to pass data from one format to another, from one object to another, we serialize, we deserialize … For much of those problems, many cook their own stuff … a piece of code that does its thing, and which is usually not so flexible and therefore not re-usable. It ends-up being not very DRY ! Recently I was working on a project implying Django, ldap and a json API ; trying to stick libraries together and endlessly transforming the same data from/to different formats. I grew tired of writing similar-looking code for doing that. So I started gathering, factorizing, generalizing this code, and came up with any2any. NB: if at this point you think “Why on earth would I ever use that ?”, maybe you should first download this example, and play with it. It is a very simple Django project demonstrating, how you can customize the output format of your API with any2any. A primer for Cast any2any’s most important class is Cast. Basically, that’s the base class for building all your transformation operations. Defining a new cast is very simple : class MyCast(Cast): setting1 = … -
Taller de Introducción a Django el 17 octubre en Madrid
El próximo lunes día 17 de Ocubre realizaremos en Madrid un Taller de Introducción a Django de la mano de Betabeers. Está orientado a gente que quiere tener un primer contacto con el framework y que todavía no lo conoce mucho (o nada). Tenéis la información en la sección de formación y en el blog de de Betabeers... -
Ordenar una query por la longitud de un campo
A veces tenemos que hacer queries un poco especiales y necesitamos ayuda de SQL cuando el ORM de Django se nos queda pequeño. Aquí tenemos un ejemplo de cómo ordenar una query a la base de datos por la longitud de un campo... -
Django admin magic screenshots
-
Caktus 2012 Summer Internship Program
I'm excited to announce that Caktus is looking for candidates for our summer internship program. It is a 12 week paid position in our Carrboro, NC office. We're driving distance from UNC Chapel Hill, NC State Univeristy in Raleigh, and Duke in Durham, so students from all parts of the NC Research Triangle are welcome ... -
Caktus 2012 Summer Internship Program
I'm excited to announce that Caktus is looking for candidates for our summer internship program. It is a 12 week paid position in our Carrboro, NC office. We're driving distance from UNC Chapel Hill, NC State Univeristy in Raleigh, and Duke in Durham, so students from all parts of the NC Research Triangle are welcome ... -
Caktus 2012 Summer Internship Program
I'm excited to announce that Caktus is looking for candidates for our summer internship program. It is a 12 week paid position in our Carrboro, NC office. We're driving distance from UNC Chapel Hill, NC State Univeristy in Raleigh, and Duke in Durham, so students from all parts of the NC Research Triangle are welcome ... -
Load Testing with JMeter: Part 2 - Headless Testing and Jenkins Integration
If you read part 1 of my JMeter series, you now know how to create a JMeter performance test with as much complexity as you need to hit every part of your application and push it to its limits. As mentioned at the end of the post, though, when running your test plan from your local machine you are often limited by bandwidth. The test plan may not be able to fully stress your application because it can’t transfer data fast enough for all of your concurrent connections. To really push your application hard, you need to run your load test from the same local network that your application runs within. -
Cómo importar un archivo CSV (ó TSV) en un modelo de django
Mitch Fournier explica en su blog cómo importar datos en formato CSV a un modelo de Django, tal cómo lo ha utilizado en su proyecto Wantbox.com. Primero creamos un modelo que contenga los mismos campos que el archivo CSV que queramos importar, utilizando el tipo de campo más adecuado para cada uno de ellos dependiendo de si sus valores van a ser cadenas de texto, números, fechas... -
I'm writing a Django book
-
How To Import a CSV (or TSV) file into a Django Model
Recently I downloaded a US zip code data file in comma separated (CSV) format. Below are the steps and python script that I used to import that data into a django model for my site Wantbox.com. The Steps to Import CSV Data into Django: Create your django model (mine is called “ZipCode”, see below). Create [...] -
First steps with Compass
A lightning talk by Thijs Jonkman at the Dutch Plone User Day once again brought Compass to my attention. I’ve read about it on other occasions, but I never actually tried it. But Thijs really made me want to try it for myself. First of all a bit of explanation about Compass. According to the website it is an “open source CSS authoring framework which uses the Sass stylesheet language."1 Let’s process this backwards… Sass, which stands for “Syntactically Awesome Stylesheets”, is an extension of CSS3 and it adds a lot of useful features (e.g. variables, and mixins). These features make CSS development a lot easier. (And, speaking as a Python developer, more fun.) Compass is a framework that makes working with Sass even better. Its core contains all kinds of useful mixins for e.g. CSS resets, CSS3 borders, a footer that sticks to the bottom of the page and code to help you with sprites, to name just a few. And if you need more than Compass delivers out of the box, there are many more plugins available. Getting started To get an impression of Compass, I decided to retrofit the CSS for this website with Compass. Luckily Brandon … -
Django pro tip: if you only use the admin
If you have a project that only exposes the admin you should just use the 500/404 templates from the admin. Put this in your project’s urls.py: from django.utils.functional import curry from django.views.defaults import server_error, page_not_found handler500 = curry(server_error, template_name='admin/500.html') handler404 = curry(page_not_found, template_name='admin/404.html') I wonder why django doesn’t mention those templates in the docs … If you have other drop-in apps that need authentication (like rosetta or sentry) bare in mind that the admin doesn’t have a reusable login view so you must hook one. You should just reuse django admin’s login template. Put this in the urlpatterns (don’t forget to match it to LOGIN_URL in the settings): url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}), You might note that this is not very DRY but actually the LOGIN_URL might differ than the one in the urlpatterns (eg: you mount the django wsgi handler on a non-root path). Tagged: django, python -
Django pro tip: if you only use the admin
If you have a project that only exposes the admin you should just use the 500/404 templates from the admin. Put this in your project's urls.py: from django.utils.functional import curry from django.views.defaults import server_error, page_not_found handler500 = curry(server_error, template_name='admin/500.html') handler404 = curry(page_not_found, template_name='admin/404.html') I wonder why django doesn't mention those templates in the docs ... If you have other drop-in apps that need authentication (like rosetta or sentry) bare in mind that the admin doesn't have a reusable login view so you must hook one. You should just reuse django admin's login template. Put this in the urlpatterns (don't forget to match it to LOGIN_URL in the settings): url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}), You might note that this is not very DRY but actually the LOGIN_URL might differ than the one in the urlpatterns (eg: you mount the django wsgi handler on a non-root path). -
Django pro tip: if you only use the admin
If you have a project that only exposes the admin you should just use the 500/404 templates from the admin. Put this in your project's urls.py: from django.utils.functional import curry from django.views.defaults import server_error, page_not_found handler500 = curry(server_error, template_name='admin/500.html') handler404 = curry(page_not_found, template_name='admin/404.html') I wonder why django doesn't mention those templates in the docs ... If you have other drop-in apps that need authentication (like rosetta or sentry) bare in mind that the admin doesn't have a reusable login view so you must hook one. You should just reuse django admin's login template. Put this in the urlpatterns (don't forget to match it to LOGIN_URL in the settings): url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}), You might note that this is not very DRY but actually the LOGIN_URL might differ than the one in the urlpatterns (eg: you mount the django wsgi handler on a non-root path). -
Caktus Hosts 3rd Django Sprint in North Carolina
Here at Caktus, we love Django and use it to make all of our web applications. To help support the Django community, we are hosting a development sprint on November 12th and 13th at our office in Carrboro, NC in preparation for the 1.4 release. The sprint is a great is an excuse for people to ... -
Caktus Hosts 3rd Django Sprint in North Carolina
Here at Caktus, we love Django and use it to make all of our web applications. To help support the Django community, we are hosting a development sprint on November 12th and 13th at our office in Carrboro, NC in preparation for the 1.4 release. The sprint is a great is an excuse for people to ... -
Caktus Hosts 3rd Django Sprint in North Carolina
Here at Caktus, we love Django and use it to make all of our web applications. To help support the Django community, we are hosting a development sprint on November 12th and 13th at our office in Carrboro, NC in preparation for the 1.4 release. The sprint is a great is an excuse for people to ... -
Making Django's signals asynchronous with Celery
Update: A comment on the ticket I opened by Alex Gaynor brought up a point that I hadn't fully considered. It's worth noticing before going further in this post and also worth pointing out my monkey patch doesn't answer this question. After speaking with Carl, I'm marking this as wontfix because it is non-obvious as to whether pickling a Signal should include the registered receivers, and how that interacts with the weak referencing, since there's no obvious semantic it seems better not to guess. I really enjoy working with both Django's signal framework and Celery tasks. Today it occured to me that it would be useful to combine the two and have “asynchronous signals”. Here is the solution that I came up with, read on below if you want to see how I arrived at this and why we need to monkey patch. from celery.task import task from django.db.models.signals import post_save from myproject.models import MyModel # Warning. Monkey patch. from django.dispatch.dispatcher import Signal def reducer(self): return (Signal, (self.providing_args,)) Signal.__reduce__ = reducer # With the patch done, we can now connect to celery tasks. @task(ignore_result=True) def async_post_save(sender, instance, **kwargs): # do something with the instance. pass post_save.connect(async_post_save.delay, sender=MyModel) The first solution … -
From server hater to server lover
From server hater to server lover -
Improve Django SQL Queries Using Debug Toolbar
Django’s database querying is there to make life easier but it’s also easy to forget about the SQL that is still generated under the hood. When using Django’s query objects it’s extremely difficult to know how often the database is being hit and with what SQL queries. We often write queries in our views, check [...] -
Django CMS Plugins with selectable template …
A simple explanation how to create Django CMS plugins that allow the administrator to select different templates. This is extremely useful if you need to use the same plugin in several sections with different designs. -
django and jQuery templates
KnockoutJS is a great way to create relationships between data objects, and interface elements. You can, for instance, bind a date value to an html ``input[type=date]`` element, and have it converted into a proper date object. You could then display data based on this, or do anything else you wanted. KnockoutJS 1.2 (the currently stable version) defaults to using jQuery templates (jQuery-tmpl), which happen to use conflicting syntax to django templates. For instance, if you were to have the following in your django template file: {% highlight html+django %} {{ "{{if foo > bar"}} }} Stuff Here {{ "{{/if"}} }} {% endhighlight %} Then django would attempt to process that, as it uses bits that look like django's template engine's value placeholder. A workaround to this is to look at doing something like wrapping any jQuery templates in something that prevents django from interpreting it. But I don't like that solution. For starters, almost every text editor will try to syntax highlight data between `` -
Why CustomUser subclasses are not such a good idea
### Background The system I work on has People who may or may not be Users, and very infrequently Users who may not be a Person. In fact, an extension to the system has meant that there will be more of these: a User who needs to be able to generate reports (say, a Franchisor who needs to only be able to access aggregate data from franchises, that might belong to multiple companies) who is never rostered on for shifts, which is what the Person class is all about. Anyway, the long and the short of this was that I thought it might be a good idea to look at sub-classing User for ManagementUser. I guess I should have listened to those smarter than me who shouted that sub-classing User is not cool. Although they never gave any concrete reasons, but now I have one. You cannot easily convert a superclass object to a specialised sub-class. Once a user is a User, it's hard to make them into a ManagementUser. It can be done: the following code will take a User (or any parent class) object, a User (or whatever) subclass, and any other keyword arguments that should be passed … -
Improve Django SQL Queries Using Debug Toolbar
Django’s database querying is there to make life easier but it’s also easy to forget about the SQL that is still generated under the hood. When using Django’s query objects it’s extremely difficult to know how often the database is being hit and with what SQL queries. We often write queries in our views, check that they return what we want, then forget them. Lots of the time that is okay but often we’ll run into performance problems later down the road due to too many database queries. Even if you only have one query in your view, the template might generate more queries without you knowing about them. Luckily we have the django debug toolbar to show us how many queries are being sent to our database for a single page request. So I’m going to go through an example of using the debug toolbar to make a performance improvement for a django view. I’m not going into how to install the debug tool bar because it’s all on their download page here. I created a simple test site to demonstrate how to find and improve database hits. It has one page which just lists a load of comments …