Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Welcome Jacob Kaplan-Moss
I'm very pleased to announce that Jacob Kaplan-Moss has joined Revolution Systems to head up a new line of services around the ever growing Django web development framework. First up are commercial Django Support Plans, but look for more Django related offerings in the near future. Jacob has been a good friend of mine since before Django was even released.  It was a pleasure to work with him at our previous day jobs and I'm very excited for the future ahead.  Not only is he obviously an authority on Django, he's an amazing developer and generally an expert on all things tech. Jacob and Adrian are both great examples of how to lead an Open Source project and grow a real community around it.By offering Django Support packages we hope to help adoption of Django in the business world, which helps grow the community at large.   -
Easier field translation with django-transmeta
django-transmeta is a new project that provides django field translations in a simpler way than existing ones like django-multilingual and transdb.The basis of that simplicity is creating a field in the database table for every translation, so internally we'll have something like:CREATE TABLE app_model ( [...] myfield_en varchar, myfield_ca varchar, [...]);where "en" and "ca" are the languages in our application (English and Catalan in this case).For the developer, translating a model is as simple as adding a metaclass to the model, and specify the fields to translate in its Meta class:from transmeta import TransMetaclass MyModel(models.Model): __metaclass__ = TransMeta name = models.CharField(max_length=64) description = models.TextField() price = models.FloatField() class Meta: translate = ('name', 'description', )Even with this project is still as tricky as transdb and multilingual, its main goal is being really really simple, for its design, for developers, and its code (that mainly it's about 120 lines of code). It also breaks some limitations of transdb (its most simple predecessor IMHO) like translating non-text fields.I also want to mention that I just discovered a new project for translating model fields, named django-modeltranslation, that looks cool, but I don't like the (admin like) registering way to set translatable fields (too much complicated). -
It's time for a change
It’s the era of change, I suppose… Starting today I’m joining Frank Wiles – a good friend and fellow Lawrencian – at his consulting firm, Revolution Systems, LLC. I’m really excited to be working with Frank: he’s a great guy, and a crazy-smart developer and sysadmin. Together, we’re going to be offering professional Django support to companies who need a Django expert on staff, but can’t afford someone full-time. The Django community is terrific; those who are comfortable with the IRC/mailing list support venue can get great assistance that way. -
Django Brasil no Twitter
Agora os artigos coletados pelo agregador de feeds da comunidade serão publicados no Twitter, isso graças à colaboração do djangonauta Arthur Furlan (valeu Arthur, a comunidade agradece!). Então, quem deseja acompanhar a comunidade brasileira de Django pelo Twitter, inscreva-se no @djangobrasil. E se você ainda não possui seu blog cadastrado em nosso agregador de feeds, envie para nós o link para o feed da tag (ou categoria) "Django". Colaborações com código para o site são muito apreciadas e estamos precisamos de mais. Se interessar, acesse a página do projeto. -
Revisiting long running processes in Django
So in my last post on this topic I discussed different ways to handle the problem of running code that wold otherwise cripple your web server, by pushing them off to another process. It was mentioned that there may be other ways to attack the problem, either through Python threads or Django’s signals. This post is a review of those two suggestions. Django’s signals I’ll attack the simpler option first, since the response to whether this solution is viable takes all of one word: no. Signals are not asynchronous by nature and therefore they do not work as a solution to the problem. It is true that you can setup signals to work asynchronously, but you’d have to employ one of the methods discussed to handle that. So if you were to use signals to handle some asynchronous work then all they would really be doing is changing the layout of that code. You’d still need something else to actually handle the asynchronous work. I’ll offer up a simple example of how signal code looks just for completeness. There are three pieces to signals. 1.The signal itself 2.The sending of the signal 3.The listeners of the signal 1. Setting up … -
Full Django Serializers - Part II
In the first part of this article I covered the excludes and extras options to the Wad of Stuff serializer. In this article I introduce the relations option.RelationsThe Wad of Stuff serializers allow you to follow and serialize related fields of a model to any depth you wish. This is why it is considered a "full serializer" as opposed to Django's built-in serializers that only return the related -
Fast Caching with Django and Nginx
I've been toying with optimizing the caching on my blog recently – for my own interest (this humble blog doesn't get all that much traffic). All the same, any speed improvements will only mean snappier page-loads and greater capacity to handle a slashdotting, or similar. I discovered that Nginx has a memcached module that can serve pages directly from memcached without touching the file-system, or a downstream web-app. Which makes for very fast response times. To get it working, you need to set a cache key named with the url of the page, and the value to the HTML. Alas, this means that it would not work with Django's caching mechanism due to the way Django caches unique pages based on the contents of the request header. -
Fast Caching with Django and Nginx
I've been toying with optimizing the caching on my blog recently – for my own interest (this humble blog doesn't get all that much traffic). All the same, any speed improvements will only mean snappier page-loads and greater capacity to handle a slashdotting, or similar. I discovered that Nginx has a memcached module that can serve pages directly from memcached without touching the file-system, or a downstream web-app. Which makes for very fast response times. To get it working, you need to set a cache key named with the url of the page, and the value to the HTML. Alas, this means that it would not work with Django's caching mechanism due to the way Django caches unique pages based on the contents of the request header. Still, the promise of serving up cached pages without even touching Django was most tempting. So I took the cache middleware from Django and butchered it so that it created a simple enough cache key for Nginx to handle. Here's the code that generates a cache key, given a request: def get_cache_key(request, key_prefix=None): if key_prefix is None: key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX cache_key = '%s.%s' % (key_prefix, request.path) return cache_key The following snippet, taken from … -
Django, MySQL & UTF-8
Last week I finally decided to switch my hosting service from MediaTemple to SliceHost. I have been postponing this move for almost a year, since I simply didn’t have the time to redeploy ten separate domains and move all their e-mail accounts. But, in a moment of foolishness, I cancelled my MediaTemple account and opened a brand new SliceHost one with Ubuntu 8.04 - little did I know what I was getting myself into… Actually, the move was pretty painless. MediaTemple’s insistence on using CentOS has been putting me off for the past couple of years, and redeploying my Django sites basically meant changing a few lines in my Fabric deployment scripts. I had been forwarding all my mail to separate Gmail accounts for a while now, so I ended up opening a Google for Domains account and that was ready as well, after some DNS setup. The only problem I faced was with MySQL, as I had expected. I never use MySQL for new projects anymore, Postgres provides a much more robust and consistent solution. However, my MediaTemple service didn’t have a PostgreSQL server, so all my Django projects had to run on MySQL. I did mysqldumps on the … -
Eldarion Logo
Those of you who follow my good friend James Tauber on twitter, facebook or through the Pinax Project have already heard that James has resigned from mValent. -
Ordering related objects in Django
Django models have a meta option order_with_respect_to that allows you to order objects within the scope of a related ForeignKey object.This option adds an _order column to the model's database table to keep track of this ordering.That's all very well, but if you need to change the sequence order you may well feel at a loss. The official documentation makes no mention of this option beyond a basic explanation of its purpose , and editing your objects in the built in admin app reveals no user interface for changing the ordering either. [1]Update Feb 2009: There's now a ticket for this functionality to be added to the docs.I managed to uncover a Python interface by delving into Django's API internals [2]. An object with related models that order with respect to it is given two handy methods:get_RELATED_order()set_RELATED_order()where RELATED is the lowercased model name of the ordered objectsclass Entry(model.Model): # ... fieldsclass Comment(model.Model): entry = model.ForeignKey(Entry, related_name='comments') # ... more fields class Meta: order_with_respect_to = 'entry'Given the above example models, you can retrieve the order of an entry's comments:>>> entry = Entry.objects.latest()>>> entry.get_comment_order()[1, 2, 3, 4]And change the ordering by passing a list of comment ids back in.>>> entry.set_comment_order([2, 1, 4, … -
Serving Django via CherryPy behind cherokee
Almost one year ago "Peter Baumgartner" wrote about Serving Django via cherrypy I am going to explain in this post how to take this approach one step further and to add load and balancing of the requests to several instances of cherrypy. This sounds like a lot of "*.conf" editing, isn't it ? In fact the nice thing about this approach is that the only file you will have to edit is your settings.py to add one line. To do so I am going to use cherokee mainly because it has a user friendly interface called cherokee-admin which provides a very easy way to configure your server. For this article I have used cherokee Version 0.98.1.I will assume in this article that you have a working django project in a virtualenv. First you will need to install cherrypy and django-cpserver. You have several way to do this the easier is probably to use pippip install cherrypypip install -e git://github.com/lincolnloop/django-cpserver.git#egg=django-cpserverThen you need to edit you settings.py to add "django_cpserver" in the list of your INSTALLED_APPS. This will give you a convenient django management command to start cherrypy server../manage.py runcpserver port=8089Believe it or not this was the hardest part of the recipe … -
Django: DRY Custom Model Forms and Fields
With the release of Django 1.0, the ability to add a list of validators to a model field was removed. This was replaced with the clean*() methods in the new forms classes. Unfortunately when you write your own form subclasses you may end up repeating a lot of the parameters in your form field definitions that you had already declared in your model fields such as max_length, required, help_text, -
Error común en upload_to de ImageFields y FileFields
Hoy me he topado con un artículo sobre un error muy común al utilizar ImageField ó FileField. Al usar cualquiera de estos dos tipos de campo podemos especificar la ruta relativa a nuestro setting MEDIA_ROOT en la que queremos que se guarde el archivo subido mediante el argumento upload_to... -
More on extended-markup
In my last post I introduced extended-markup, which is the light-weight markup system used to generate posts in Django-Techblog. I'll cover a few other things it can do in this post. When the Post model is saved to the database, the extended markup is parsed in to a structure that is basically a dictionary containing a list of chunks, and associated variables. The order that the chunks appear in each section is the same as the order they appear in the markup, unless a chunk variable called priority is defined. This causes the chunks to be sorted in descending order of priority, chunks without a priority value are assigned a default of 100. -
Django Techblog markup system
Django Tech Blog is now running my blog. It is only fitting that my first post on the new system is about the technology behind it. I never intended to compete with Wordpress on number of features, and Techblog was never intended to be an all-things-to-everyone type of web application, but I can boast a few features that set it apart. I'll cover some of those features in future posts, for now I would like to go over the light-weight markup language I use for posts. -
Descubriendo objetos similares por sus etiquetas 2
Ya hablamos anteriormente sobre cómo descubrir objetos similares por sus etiquetas con la versión 1.0 de Django. Sin embargo la versión de desarrollo de Django incluye funciones de agregación que nos permiten realizar este tipo de tareas de una manera más cómoda sin tener que utilizar SQL puro como hacíamos antes. Partiremos exactamente del mismo código que usamos la vez anterior: Dos modelos definidos en el archivo models.py de nuestra aplicación... -
Nashvegas: A Simple Django Migration Tool
Introduction Back in July I discussed how I built a tool to help manage database changes across a team and through deployment for our Django based project. And yes, I am aware of other approaches/projects tackling this same problem. None of them seemed to work how I wanted them to as they all seemed to focus on trying to keep you from writing the raw sql yourself. I am comfortable with writing SQL and for something that will execute automatically against production databases, I prefer to have that control in knowing exactly what will get executed. Yes, many of these tools have options to allow me to preview the generated SQL, but it still gave me the feeling of being boxed in. For your reference, here are the ones I reviewed: South dmigrations django-evolution deseb yadsel schema-evolution So I abstracted out the script and it's assumptions about our environment to function as a management command in a stand alone reusable app. My Approach It's extremely simple and is based purely on executing SQL statements in order based on it's file naming scheme. Basically, you create a folder somewhere in your project -- I call mine "db". Within this folder you … -
Nashvegas: A Simple Django Migration Tool
Introduction Back in July I discussed how I built a tool to help manage database changes across a team and through deployment for our Django based project. And yes, I am aware of other approaches/projects tackling this same problem. None of them seemed to work how I wanted them to as they all seemed to focus on trying to keep you from writing the raw sql yourself. I am comfortable with writing SQL and for something that will execute automatically against production databases, I prefer to have that control in knowing exactly what will get executed. Yes, many of these tools have options to allow me to preview the generated SQL, but it still gave me the feeling of being boxed in. For your reference, here are the ones I reviewed: South dmigrations django-evolution deseb yadsel schema-evolution So I abstracted out the script and it's assumptions about our environment to function as a management command in a stand alone reusable app. My Approach It's extremely simple and is based purely on executing SQL statements in order based on it's file naming scheme. Basically, you create a folder somewhere in your project -- I call mine "db". Within this folder you … -
FAQ: Untrusted users and HTML
An input form that takes raw HTML. It’s a pretty common thing to see in web apps these days: many comment forms allow HTML, or some subset thereof; many social-network-style applications allow end-users to enter HTML in their profiles; etc. Unfortunately, allowing untrusted users to enter raw HTML is incredibly dangerous; read up on XSS if you don’t know why. So a common question that comes up in web developer circles deals with how best to “escape” user-entered HTML so that is safe for presentation. -
sPaste Update
After a bit of a break, there is now a bit of new functionality in sPaste. Now when creating a snippet users can select a date and a number of views, after which the snippet will self-destruct. This update adds a great extra layer of security by only allowing information to exist in sPaste just [...] -
django full text search with solango
2 months ago I wrote a post titled "django fulltext search part-1" this post was explaining how to take advantage of djangosearch to interface between django and solr.The big advantage of djangosearch is the fact that it comes with a plugable backend architecture. This can be a strength since in theory it enables you to abstract the details of the the full text engine you are using however in practice I ended up writing a patch to bypath the abstraction layer because it was preventing me of doing the query I wanted. So to make a long story short djangosearch was not working out of the box for my needs.However 2 week ago Sean Creeley released solango and this significantly changed landscape of full text search in the django eco-system. I will not go in the details about solango in this post. It comes with some management commands that are so convenient that I still wonder why I haven't thought at implementing them on top of djangosearch. I will copy below a short extract form the documentation which is excellent :./manage.py solr --help#solango schema options--fields Prints out the fields the schema.xml will create--flush Will remove the data directory from Solr.--reindex … -
QueryDict and update()
QueryDict and update() -
Parsing unescaped urls in django
Modern browsers escape urls automatically before sending them to the server, but what happens if your application serves http requests to clients that doesn't escape urls?The answer is that can get unexpected results if you server works in Django (and probably in any python framework/application). That's because python's BaseHTTPServer.BaseHTTPRequestHandler handles urls according to standards, not from a human point of view.Let's see with an example, consider the next request:http://vaig.be/identify_myself?name=Marc Garcia&country=Cataloniaif you request it with a browser, it will escape the space in the url, so the server will get:http://vaig.be/identify_myself?name=Marc%20Garcia&country=Cataloniabut what if the client uses, for example, python's urllib2.urlopen without escaping (using urllib.quote)? Of course it is a mistake, but you, as server side developer can't control your clients.In that case the whole request that server receives is:GET http://vaig.be/identify_myself?name=Marc Garcia&country=Catalonia HTTP/1.1and after being processed (splitted) by python's BaseHTTPServer.BaseHTTPRequestHandler, what we'll get from django is:request.method == 'GET'request.META['QUERY_STRING'] == 'name=Marc'request.META['SERVER_PROTOCOL'] == 'Garcia&country=Catalonia HTTP/1.1'so our request.GET dictionary will look like:request.GET == {'name': 'Marc'}what is not the expected value (from a human point of view).So, what we can do for avoiding this result is quite easy (and of course tricky), and is getting the GET values not from django request.GET dictionary but from the one … -
Washington Times releases open source projects
The Washington Times has always focused on content. After careful review, we determined that the best way to have the top tools to produce and publish that content is to release the source code of our in-house tools and encourage collaboration. The source code is released under the permissive Apache License, version 2.0. The initial tools released are: django-projectmgr, a source code repository manager and issue tracking application. It allows threaded discussion of bugs and features, separation of bugs, features and tasks and easy creation of source code repositories for either public or private consumption. django-supertagging, an interface to the Open Calais service for semantic markup. django-massmedia, a multi-media management application. It can create galleries with multiple media types within, allows mass uploads with an archive file, and has a plugin for fckeditor for embedding the objects from a rich text editor. django-clickpass, an interface to the clickpass.com OpenID service that allows users to create an account with a Google, Yahoo!, Facebook, Hotmail or AIM account. The opensource.washingtontimes.com web site will be hosting the code and issue tracking software, using django-projectmgr. Update: All our projects are now hosted at GitHub.