Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Measure your code
I found a cool tool today to measure code: metrics. It measures SLOC, comments and cyclomatic complexity. It's easy to install: pip install pygments metrics Run this in your project's root: metrics -v `find . -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` I have a django project so I added \! -path "*/migrations/*.py" to skip any files that are in a migrations dir (I'd skip the automatically generated south migrations). You probably bundle other libraries or apps in your source tree (eg: jquery or that nice django app the author didn't bother to make a setup.py script for) so you want to measure only some specific paths. Eg, to collect stats only for files in src/foobar, lib/tools and src/otherbar: metrics -v `find src/foobar lib/tools src/otherbar -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` If you work on multiple projects you can make a script or alias for this: metrics -v `find \`cat METRICS\` -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) … -
Be careful how you use static variables in forms
Working on django-uni-form I came across with a weird situation and it took me some time to figure out what was going on. I wouldn’t say it was a bug, it was more a misuse or a documentation problem. After that, I realized other coders make the same mistake that was affecting us, so I thought about writing an article for warning Python/Django programmers. If you are building a Django application in which you add attributes to a form, that are not form fields, like in this example: class ExampleForm(forms.Form): description = forms.CharField( label = u"Short description", max_length = 40, ) type_of_form = 'dangerous' You should know that every attribute that is not a form field, such as type_of_form, is static or a class-wide variable. Let’s see what this means and please stay with me till the end, don’t switch channel. If you handle a form instance in one of your views and change type_of_form value: form = ExampleForm(request.POST) form.type_of_form = "secure" Then type_of_form turned into an instance-level variable. Which means only that specific form instance has a type_of_form set to ‘secure’. You can still access the class wide variable, using the class name: >>> ExampleForm.type_of_form 'dangerous' Things get complicated … -
Be careful how you use static variables in forms
Working on django-uni-form I came across with a weird situation and it took me some time to figure out what was going on. I wouldn’t say it was a bug, it was more a misuse or a documentation problem. After that, I realized other coders make the same mistake that was affecting us, so I thought about writing an article for warning Python/Django programmers. If you are building a Django application in which you add attributes to a form, that are not form fields, like in this example: class ExampleForm(forms.Form): description = forms.CharField( label = u"Short description", max_length = 40, ) type_of_form = 'dangerous' You should know that every attribute that is not a form field, such as type_of_form, is static or a class-wide variable. Let’s see what this means and please stay with me till the end, don’t switch channel. If you handle a form instance in one of your views and change type_of_form value: form = ExampleForm(request.POST) form.type_of_form = "secure" Then type_of_form turned into an instance-level variable. Which means only that specific form instance has a type_of_form set to ‘secure’. You can still access the class wide variable, using the class name: >>> ExampleForm.type_of_form 'dangerous' Things get complicated … -
DjangoCon Europe videos posted
DjangoCon Europe 2011 videos online A bit late to the game perhaps, since people already started tweeting links to the videos before me having time to actually link the videos to the talks. But hey, that shouldn’t spoil the game: The videos are now online, and can be found in te schedule on the details pages of all the talks, including the slides. For example to check out Eric Florenzano’s excellent opening keynote, check out this talk page. The video of Alex’ talk on monday is forthcoming. I would like to use the opportunity to thank our Kryptonite sponsors, who made such a large contribution to DjangoCon Europe 2011, once more: Fabrique: Who in addition to being a kryptonite sponsor also sponsored the cocktail bar on Monday and the massages/relaxing area on Tuesday. I amsterdam: Who in addition to being a kryptonite sponsor also sponsored the free bikes for conference goers and the massages during both the sprint days. A warm thank you from all of us. -
Award Winning Satchmo Sites
The team at Pemaquid Communications have been successfully using Satchmo and Django to create innovative sites for their clients. Recently they won several Best of the Web awards at the TechMaine Gala. -
django-meio-easytags 0.4 released!
I just released the version 0.4 of the django-meio-easytags. I added a subclass of django’s default template tags Library. And now it’s easier to create a template tag. Take a look. Projects page Read the Docs Download from Github -
django-meio-easytags 0.3 released!
I released today the version 0.3 of django-meio-easytags. Now it supports template tags that accepts positional arguments (*args) and keyword arguments (**kwargs). If you don’t know how to use this, take a look at Python FAQ. In this release I included some documentation and created a page for the project. Any doubts, suggestions, feature requests, feel [...] -
Documenting Django pluggable apps with Sphinx
I decided to document my Django projects with the same tool used by Django team: Sphinx. It is a very good documenting tool, and was used for many other projects, including the Python Project itself. But it has a simple problem with Django, that I found the solution rlazo’s blog. But it still has some problems, [...] -
django-meio-easytags released!
django-meio-easytags An easy way to create and parse custom template tags for Django's templating system. -
Django ORM now supports fields references in filters
Today was added a new feature to django ORM. Now it supports references to fields in filters expressions. Just checkout the SVN version and enjoy it. Before this update, queryset could be filtered only by absolute values. queryset.filter(field='absolute value') Will generate somthing like this: SELECT * FROM table_name WHERE field = 'absolute value'; Now you can filter by another’s table [...] -
get_first_object_or_none shortcut for Django
I will talk about a shortcut I developed for the Django framework and always use in my apps. This code is aimed in making a quik shortcut to obtain the first object of a queryset if it exists or None otherwise. It’s very useful when you want to display the last news in the first page [...] -
Arquivos do Mini curso de Django disponibilizados
No dia 24 de abril de 2009, no SENAC em Natal/RN, ocorreu o FLISOL. Neste evento, eu ministrei um mini curso de django. Então estou disponibilizando tanto os arquivos_mini_curso desenvolvido durante o curso, como os slides. Mini curso introdutório ao DjangoView more presentations from vbmendes. -
Festival Latino-americano de Instalação de Software Livre
Venho através deste convidá-los ao FLISOL/RN 2009. O Festival Latino-americano de Instalação de Software Livre do RN irá acontecer no dia 25 de abril de 2009 no SENAC em Natal. No evento eu irei ministrar um mini-curso introdutório ao framework Django das 14:00 as 17:00 horas, cujo objetivo é formar pessoas com conhecimentos básicos acerca do [...] -
Reffering to Django docs from your docs using Sphinx
Sphinx is a great documentation tool, and one of it’s built-in extensions is sphinx.ext.intersphinx. It simply takes your objects references for other projects and converts to links in the other project’s documentation. In sphinx-quickstart command, it asks if you want to add this extension. If so, It adds this code to your conf.py file: extensions = ['sphinx.ext.intersphinx'] intersphinx_mapping [...] -
MEDIA_URL and context from processors available in HTTP 500 template
It’s easy to create a custom template for HTTP 500 errors. All you have to do is create a file named 500.html in any of the application’s TEMPLATE_DIRS. But in almost all cases you want to use media in this page. It’s good to have an error page with the same look and feel of [...] -
Django Production Error Handler
I am working on an application that, besides providing a dynamic website, also talks to an iPhone application. What happens when the iPhone, or a web visitor, triggered a bug in the application? Django actually provide a nice mechanism to report error in its “batteries included” goodness. You can easily setup the Django environment so [...] -
Jacob Kaplan-Moss on DevOps
Jacob gave a talk at the Boston Django Meetup this month on the topic of DevOps — The role of the developer and the role of sysadmin are merging, and it is a good thing. This idea certainly resonate with me. I started my career as a DevOps by necessity — I worked with a [...] -
Django CSRF Migration
Like many of you, I am migrating all my Django sites to Django 1.2.1. For sites that are currently in production, I am doing the slow migration route. Just trying to get the site up with 1.2 without using any of the new features yet. One thing that I ran into is the new CSRF [...] -
My Accidental Connection with Senator Ted Kennedy
Being Chinese in Boston, I always hear positive stories about the late Senator Ted Kennedy helping immigrants. In addition, I agree with most of his political views, he seemed like a good Senator. After learning of his death, I felt we had lost a great man. I added one of his biographies to my Amazon [...] -
Fix Python source code to use spaces instead of tabs
What if someone gave you a Python source file that is indented using tabs? If you are using emacs, the following will let you convert it back to using spaces: # first set the buffer tab width to 4 (or whatever you like) M-x set-variable <return> tab-width <return> 4 # then mark the entire file [...] -
I am in the NY Times, sorta
Check out the NYTimes article on WilsonDailyPrep. We at Imperial Consulting did the application, using Django and Python. It is a great service and a lot of fun to work on (my own vocab and grammar has gotten better, the Math quizzes are too easy). I am glad it is getting the big time publicity [...] -
Serving favicon in an Django App using Apache
I got a free few minutes to work on my own site here. Since I migrated the site from all static pages to Django served, I still haven’t put back the favicon icon back onto the site. The sites runs under a virtual host in apache2 at WebFaction. This is what you need to put [...] -
Upgrading to Django 1.3?
Should you upgrade to Django 1.3? Upgrade any web framework in your application in general? Try this decision chart here http://www.djangopro.com/2011/03/should-i-upgrade-to-django-1-3/: -
Django South Explained
Posted my tutorial on using Django south, the database migration tool, over at DjangoPro. Check it out! -
dojo.beer(2)
We from uxebu have organized the second dojo.beer and are happy to have won Mayflower to jump in sponsoring the location here in Munich, Germany. On friday the 5th december we will warm up with some dinner and some beer in some place here in Munich. The real thing will ...