Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Nice testimonial about django-static
My friend Chris is a Django newbie who has managed to build a whole e-shop site in Django. It will launch on a couple of days and when it launches I will blog about it here too. He sent me this today which gave me a smile: "I spent today setting up django_static for the site, and optimising it for performance. If there's one thing I've learned from you, it's optimisation. So, my homepage is now under 100KB (was 330KB), and it loads in @5-6 seconds from hard refresh (was 13-14 seconds at its worst). And I just got a 92 score on Yslow. I do believe I have the fastest tea website around now, and I still haven't installed caching. Wicked huh?" He's talking about using django-static. Then I get another email shortly after with this: "correction - I get 97 on YSlow if I use a VPN. I just found that the Great Firewall tags extra HTTP requests onto every request I make from my browser, pinging a server in Shanghai with a PHP script which probably checks the page for its content or if its on some kind of blocked list. Cheeky buggers!" It's that interesting! (Note: … -
Nice testimonial about django-static
My friend Chris is a Django newbie who has managed to build a whole e-shop site in Django. It will launch on a couple of days and when it launches I will blog about it here too. He sent me this today which gave me a smile: "I spent today setting up django_static for the site, and optimising it for performance. If there's one thing I've learned from you, it's optimisation. So, my homepage is now under 100KB (was 330KB), and it loads in @5-6 seconds from hard refresh (was 13-14 seconds at its worst). And I just got a 92 score on Yslow. I do believe I have the fastest tea website around now, and I still haven't installed caching. Wicked huh?" He's talking about using django-static. Then I get another email shortly after with this: "correction - I get 97 on YSlow if I use a VPN. I just found that the Great Firewall tags extra HTTP requests onto every request I make from my browser, pinging a server in Shanghai with a PHP script which probably checks the page for its content or if its on some kind of blocked list. Cheeky buggers!" It's that interesting! (Note: … -
Nice testimonial about django-static
My friend Chris is a Django newbie who has managed to build a whole e-shop site in Django. It will launch on a couple of days and when it launches I will blog about it here too. He sent me this today which gave me a smile: "I spent today setting up django_static for the site, and optimising it for performance. If there's one thing I've learned from you, it's optimisation. So, my homepage is now under 100KB (was 330KB), and it loads in @5-6 seconds from hard refresh (was 13-14 seconds at its worst). And I just got a 92 score on Yslow. I do believe I have the fastest tea website around now, and I still haven't installed caching. Wicked huh?" He's talking about using django-static. Then I get another email shortly after with this: "correction - I get 97 on YSlow if I use a VPN. I just found that the Great Firewall tags extra HTTP requests onto every request I make from my browser, pinging a server in Shanghai with a PHP script which probably checks the page for its content or if its on some kind of blocked list. Cheeky buggers!" It's that interesting! (Note: … -
Why I forked JSLint to JSHint
-
Why I forked JSLint to JSHint
Your sadly pathetic bleatings are harshing my mellow. —Douglas Crockford. This Friday we released JSHint, a code quality tool designed to detect errors and potential problems in JavaScript code and to enforce your team’s coding conventions.1 JSHint is a fork of JSLint, the tool wri... -
Django 1.3 patterns for older django versions — bruno.im
-
Django 1.3 patterns for older django versions
Django 1.3 is approaching fast, with tons of bugfixes but also some very interesting features. Among those, two are particularly interesting as I think they improve a lot the way we write our Django apps: class-based generic views and the new contrib.staticfiles app. Class-based views The benefits of class-based generic views are quite obvious: instead of wrapping an existing function-based generic view and/or passing it a countless number of argument, functionality can be easily extended using inheritance. Although the learning curve is steeper, it's totally worth learning. But see the docs for that, it's not the point of this post. Let's say you've got this big project that runs on Django 1.2. You're in the process of upgrading it to 1.3 but you're not ready yet, and you want to use class-based views for new features? Meet django-cbv. Django-cbv is a backport of the class-based views from django trunk that you can use with older django versions. As of writing this, you need to install it from my github fork since the package on pypi is missing an import (Update: fixed in django-cbv 0.1.5): pip install django-cbv Once installed, you just need to add to your MIDDLEWARE_CLASSES: 'cbv.middleware.DeferredRenderingMiddleware' And then … -
Dutch python meeting summary (from 16 Februari 2011)
Last Wednesday we had a fun PUN meeting in our office in Utrecht at Nelen & Schuurmans. A nice turnout with 30 people all in all. Jasper Spaans videotaped everything, so that'll turn up on blip.tv soon. My brother Maurits also made a summary. He missed the first talk (which I have) but he has a summary of my own talk (which I haven't). Trac - Christo Butcher Trac is for developers, for making developers' lives easier. About half of the participants uses trac. A core part of trac is its wiki. Interesting since version 0.12: a side-by-side editor: the wiki text format on the left and a live preview on the right. The second core part is the issue tracker. Nothing much special compared to other issue trackers, but pretty OK. The tracker is good both for bug tracking and for task/feature management. Third: source browsing. For subversion, mercurial and git (the latter two by means of plugins). The main reason Fox IT (where he works) started with Trac is this source browser. Not the tracker or the wiki, but the source browser. Handy: the timeline, for browsing all the changes (code, issues, wiki) in the system. Handy to … -
Dutch python meeting summary (from 16 Februari 2011)
Last Wednesday we had a fun PUN meeting in our office in Utrecht at Nelen & Schuurmans. A nice turnout with 30 people all in all. Jasper Spaans videotaped everything, so that'll turn up on blip.tv soon. My brother Maurits also made a summary. He missed the first talk (which I have) but he has a summary of my own talk (which I haven't). Trac - Christo Butcher Trac is for developers, for making developers' lives easier. About half of the participants uses trac. A core part of trac is its wiki. Interesting since version 0.12: a side-by-side editor: the wiki text format on the left and a live preview on the right. The second core part is the issue tracker. Nothing much special compared to other issue trackers, but pretty OK. The tracker is good both for bug tracking and for task/feature management. Third: source browsing. For subversion, mercurial and git (the latter two by means of plugins). The main reason Fox IT (where he works) started with Trac is this source browser. Not the tracker or the wiki, but the source browser. Handy: the timeline, for browsing all the changes (code, issues, wiki) in the system. Handy to … -
Connecting anything to anything with Django
I'm writing this post to introduce a new project I've released, django-generic-m2m, which as its name would indicate is a generic ManyToMany implementation for django models. The goal of this project was to provide a uniform API for both creating and querying generically-related content in a flexible manner. One use-case for this project would be creating semantic "tags" between diverse objects in the database. -
Connecting anything to anything with Django
Edit 7/11/2011 I've added documentation and an example app. Introduction I'm writing this post to introduce a new project I've released, django-generic-m2m, which as its name would indicate is a generic ManyToMany implementation for django models. The goal of this project was to provide a uniform API for both creating and querying generically-related content in a flexible manner. One use-case for this project would be creating semantic "tags" between diverse objects in the database. Connecting Models What its all about is connecting models together and, if you want, creating some metadata about the meaning of that relationship (i.e. a tag). To this end, django-generic-m2m does three things to make this behavior easier: wraps up all querying and connecting logic in a single attribute that acts on both model instances and the model class allows any model to be used as the intermediary "through" model provides an optimized lookup when GenericForeignKeys are used An example Referring back to the diagram, let's create some models (these are the same models used in the testcases): from django.db import models from genericm2m.models import RelatedObjectsDescriptor class Food(models.Model): name = models.CharField(max_length=255) related = RelatedObjectsDescriptor() def __unicode__(self): return self.name class Beverage(models.Model): # ... same as above class … -
Connecting anything to anything with Django
Edit 7/11/2011 I've added documentation and an example app. Introduction I'm writing this post to introduce a new project I've released, django-generic-m2m, which as its name would indicate is a generic ManyToMany implementation for django models. The goal of this project was to provide a uniform API for both creating and querying generically-related content in a flexible manner. One use-case for this project would be creating semantic "tags" between diverse objects in the database. Connecting Models What its all about is connecting models together and, if you want, creating some metadata about the meaning of that relationship (i.e. a tag). To this end, django-generic-m2m does three things to make this behavior easier: wraps up all querying and connecting logic in a single attribute that acts on both model instances and the model class allows any model to be used as the intermediary "through" model provides an optimized lookup when GenericForeignKeys are used An example Referring back to the diagram, let's create some models (these are the same models used in the testcases): from django.db import models from genericm2m.models import RelatedObjectsDescriptor class Food(models.Model): name = models.CharField(max_length=255) related = RelatedObjectsDescriptor() def __unicode__(self): return self.name class Beverage(models.Model): # ... same as above class … -
Connecting anything to anything with Django
Edit 7/11/2011 I've added documentation and an example app. Introduction I'm writing this post to introduce a new project I've released, django-generic-m2m, which as its name would indicate is a generic ManyToMany implementation for django models. The goal of this project was to provide a uniform API for both creating and querying generically-related content in a flexible manner. One use-case for this project would be creating semantic "tags" between diverse objects in the database. Connecting Models What its all about is connecting models together and, if you want, creating some metadata about the meaning of that relationship (i.e. a tag). To this end, django-generic-m2m does three things to make this behavior easier: wraps up all querying and connecting logic in a single attribute that acts on both model instances and the model class allows any model to be used as the intermediary "through" model provides an optimized lookup when GenericForeignKeys are used An example Referring back to the diagram, let's create some models (these are the same models used in the testcases): from django.db import models from genericm2m.models import RelatedObjectsDescriptor class Food(models.Model): name = models.CharField(max_length=255) related = RelatedObjectsDescriptor() def __unicode__(self): return self.name class Beverage(models.Model): # ... same as above class … -
Connecting anything to anything with Django
Edit 7/11/2011 I've added documentation and an example app. Introduction I'm writing this post to introduce a new project I've released, django-generic-m2m, which as its name would indicate is a generic ManyToMany implementation for django models. The goal of this project was to provide a uniform API for both creating and querying generically-related content in a flexible manner. One use-case for this project would be creating semantic "tags" between diverse objects in the database. Connecting Models What its all about is connecting models together and, if you want, creating some metadata about the meaning of that relationship (i.e. a tag). To this end, django-generic-m2m does three things to make this behavior easier: wraps up all querying and connecting logic in a single attribute that acts on both model instances and the model class allows any model to be used as the intermediary "through" model provides an optimized lookup when GenericForeignKeys are used An example Referring back to the diagram, let's create some models (these are the same models used in the testcases): from django.db import models from genericm2m.models import RelatedObjectsDescriptor class Food(models.Model): name = models.CharField(max_length=255) related = RelatedObjectsDescriptor() def __unicode__(self): return self.name class Beverage(models.Model): # ... same as above class … -
My Django tutorial at PyCon
Working on my tutorial slides for my PyCon class/tutorial/workshop last night I suddenly came to a stark realization.Out of dozens of slides, only 5 of them are Pinax specific.o.OI think this is because the slides are a condensed version of what the best and brightest in the Django and Python community think are good practices and tools. What do I mean?Jacob Kaplan-Moss on matching best practices with incredible documentation and tests.James Bennett on using small apps rather than monolithic ones.James Tauber and Brian Rosner's code in Pinax which taught me and so many others incredible Django tricks.PEP-8Zen of PythonMark Ramm on well, nearly everything but especially his critical commentaries on Django.So what does this mean?Well, I've been rethinking the mantra "Pinax is Django". It is hard to say that when users of django-cms and satchmoproject and other frameworks can't use core Pinax components. That said, users of those tools tend to rely on same foundation: Python, Django, virtualenv, and pip and growing ecosphere of Django Packages.Which leads me to realize that with just 5 slides pertaining to Pinax material in the tutorial, the Pinax Solutions class could be renamed "Django Solutions class with a bit of Pinax".And this makes a lot of … -
Renombrar nombres de archivos a ASCII
Los archivos que suben los usuarios a veces tienen nombres con caracteres no ASCII. Hoy en día casí todos los sistemas de archivos permiten encoding UTF-8, pero a veces nos podemos encontrar problemas en sistemas que no tienen UTF-8 activado o al ejecutar scripts sobre los ficheros que esperen un nombre de archivo en ASCII. Bojan Mihelac ha publicado en su blog una clase de almacenamiento que se basa en FileSystemStorage original añadiéndole la normalización de nombres de archivo a ASCII antes de ser almacenados. -
Announcing django-activitysync
Today I'm happy to announce the release of my first reusable Django app, django-activitysync. The app allows easy integration of social network activities and status updates into Django projects. I've been using it to power the activity section of this website for the past year and have been eager to decouple it into a separate application. What it provides Django-activitysync can provide functionality similar to other lifestream solutions, but its real power is as an extensible framework for aggregating, storing, and displaying any type of simple item. It currently provides built-in support for Twitter status items, Twitter searches, Google Reader shared items, and Reddit liked items. Adding support for a new network or activity type is as simple as implementing a new activity provider. Providers consist of 5 functions, one of which returns a list of simple objects containing the activity detail. Django-activitysync takes care of storage and duplicate detection. How to use it Django-activitysync is available as an installable Python package on PyPI. You will also find detailed documentation there on installation, configuration, and use. The source code itself is also available in a Bitbucket repository. Future plans This announcement marks the initial release of django-activitysync. I plan to … -
Monitoring Django with Munin
My friend and fellow Djangonaut Richard Barran, has written an excellent post about how to monitor a Django site using Munin. He’s written a couple of munin pluggins specifically for Django which he explains in the post. Essentially, Munin is a monitoring tool that lets you look at various performance aspects of your server, and is handy [...] -
Rutas relativas en los settings
Utilizar rutas relativas en nuestro settings.py en lugar de rutas absolutas permite que el proyecto no dependa del lugar en el que se encuentra en el sistema de archivos. Esto es ideal cuando utilizamos el proyecto en distintos entornos y las rutas absolutas del proyecto son distintas en cada uno de ellos, o si la ruta del proyecto puede variar en algún momento. -
Traducciones de modelos con django-transmeta
django-transmeta es una aplicación reusable que nos permite añadir traducciones a los campos de nuestros modelos. Es muy fácil de utilizar ya que crea automáticamente un campo en la base de datos por cada atributo traducible y cada idioma de nuestro setting LANGUAGES. Así, si tenemos un campo llamado nombre y nuestro setting LANGUAGES son inglés y español django-transmeta creará los campos nombre_es, nombre_en en la base de datos y al acceder directamente a atributo nombre obtendremos la traducción correspondiente al idioma que esté activo en la petición. -
My Pinax Solutions class at Pycon 2011
Heavily inspired by Zed Shaw's Learn Python the Hard Way class I'm changing the lecture style format of the Pinax Solutions class at PyCon 2011 to a more workshop-oriented format.Which means that the first half of the class we (myself and the peerless Brian Rosner) will spend on material critical for people new to Pinax or old hands who want to see what 0.9 offers. That means setting things up via virtualenv and pip, Pinax specific settings, media handling, template layout, extending core Pinax apps, use of idios to change profiles, openid/openauth, Django Packages to find Pinax approved stuff and more. That will be the foundation and our slides/handouts will be useful as cheat sheets for these critical parts in any Django application.The second half of the class will be a workshop. We'll spend the next half helping people with their personal projects, and will even have a few stock projects we can toss at people that either already are open source or could be released as open source. We won't write your project for you, but we will provide advice, guidance, and some elbow grease in getting things to work. If someone asks for something that we think the rest of the class could benefit … -
Utilizar jQuery en el admin de Django
Al personalizar alguna plantilla del sistema de administración podemos querer usar jQuery. Como el admin de Django ya hace uso de jQuery podemos utilizarlo directamente sin necesidad de incluir la propia librería. Pero enseguida nos daremos cuenta de que no podemos utilizar el alias $ ya que el admin utiliza la opción noConflict de jQuery. El alias que define el sistema de administración para usar jQuery es "django.jQuery". -
Django-admin-tools, la django app de janvier, presque à l’heure
Jusqu'à présent j'avais toujours réussi à poster mes billets de django app à l'heure. Mais là , là , j'ai une excuse. Je suis devenu papa le 31 janvier. Du coup, je n'ai vraiment pas eu le temps pour écrire mon billet de django app (les raleurs qui me diront que j'avais tout les jours d'avant ... -
Serving static files for Django on Webfaction
In my last post I wrote about the setup of Django with virtualenv on the Webfaction hosts. The post did not cover the serving of static files and will be covered here. It's always better to serve static media through an extra HTTP server/container doing nothing but serving static media files for better scaling. Normally I use nginx for this as it is small and fast. For Webfaction hosting you have two possibilities: You can add a "Static only" application that is an nginx, configure it for a separate (sub)domain and then configure your Django project to use this domain for serving the files. Wasn't that easy! Or you can use the Apache for serving the files. Create the "media" folder somewhere on your server (e.g. within the virtualenv folder: /home/<username>/webapps/<wsgi-app>/<virtualenv-dir>/media). Now adjust the apache.conf to load the modules required for serving the media and set some expiration time if you like (I used 12 hours as seen below). I'm only writing the updates to the apache.conf of the last post: EDIT: had to temporarely disable the snippet, as the host does not answer. Please check for yourself: snipt.org/embed/wmkmm -
Serving static files for Django on Webfaction
In my last post I wrote about the setup of Django with virtualenv on the Webfaction hosts. The post did not cover the serving of static files and will be covered here. It's always better to serve static media through an extra HTTP server/container doing nothing but serving static media files for better scaling. Normally I use nginx for this as it is small and fast. For Webfaction hosting you have two possibilities: You can add a "Static only" application that is an nginx, configure it for a separate (sub)domain and then configure your Django project to use this domain for serving the files. Wasn't that easy! Or you can use the Apache for serving the files. Create the "media" folder somewhere on your server (e.g. within the virtualenv folder: /home/<username>/webapps/<wsgi-app>/<virtualenv-dir>/media). Now adjust the apache.conf to load the modules required for serving the media and set some expiration time if you like (I used 12 hours as seen below). I'm only writing the updates to the apache.conf of the last post: ... # put after other LoadModule lines LoadModule alias_module modules/mod_alias.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule expires_module modules/mod_expires.so ... <VirtualHost *:1234> ... # after WSGIScriptAlias Alias /media /home/your_user_name/webapps/your_wsgi_app_name/virtualenv_directory/media/ <Directory /home/your_user_name/webapps/your_wsgi_app_name/virtualenv_directory/media> Order …