Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Writing your own template loaders
Django has three builtin template loaders which are used to get the templates for rendering. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) Writing your template loader is a awfuly easy. It is a callable which Returns a tuple of (openfile, filename) if it can find the template. Raise TemplateDoesNotExist if the templates cannot be [...] Related posts:A response to Dropping Django -
Things College Taught me that the "Real World" Didn't
A while ago Eric Holscher blogged about things he didn't learn in college. I'm going to take a different spin on it, looking at both things that I did learn in school that I wouldn't have learned else where (henceforth defined as my job, or open source programming), as well as thinks I learned else where instead of at college.Things I learned in college:Big O notation, and algorithm analysis. This is the biggest one, I've had little cause to consider this in my open source or professional work, stuff is either fast or slow and that's usually enough. Learning rigorous algorithm analysis doesn't come up all the time, but every once in a while it pops up, and it's handy.C++. I imagine that I eventually would have learned it myself, but my impetus to learn it was that's what was used for my CS2 class, so I started learning with the class then dove in head first. Left to my own devices I may very well have stayed in Python/Javascript land.Finite automaton and push down automaton. I actually did lexing and parsing before I ever started looking at these in class (see my blog posts from a year ago) using … -
Another Pair of Unladen Swallow Optimizations
Today a patch of mine was committed to Unladen Swallow. In the past weeks I've described some of the optimizations that have gone into Unladen Swallow, in specific I looked at removing the allocation of an argument tuple for C functions. One of the "on the horizon" things I mentioned was extending this to functions with a variable arity (that is the number of arguments they take can change). This has been implemented for functions that take a finite range of argument numbers (that is, they don't take *args, they just have a few arguments with defaults). This support was used to optimize a number of builtin functions (dict.get, list.pop, getattr for example).However, there were still a number of functions that weren't updated for this support. I initially started porting any functions I saw, but it wasn't a totally mechanical translation so I decided to do a little profiling to better direct my efforts. I started by using the cProfile module to see what functions were called most frequently in Unladen Swallow's Django template benchmark. Imagine my surprise when I saw that unicode.encode was called over 300,000 times! A quick look at that function showed that it was a perfect … -
Announcing django-admin-histograms
This is just a quick post because it's already past midnight here. Last week I realized some potentially useful code that I extracted from the DjangoDose and typewar codebases. Basically this code let's you get simple histogram reports for models in the admin, grouped by a date field. After I released it David Cramer did some work to make the code slightly more flexible, and to provide a generic templatetag for creating these histograms anywhere. The code can be found on github, and if you're curious what it looks like there's a screenshot on the wiki. Enjoy. -
Continous sphinx build
I have always found the cycle : Edit the documentation source => build the sphinx based documentation [1] => open a browser pointing the updated documentation and re iterate until your are satisfied a bit painful.Today I have finally found an automated version of this workflow that gave me one of this nice WAHOUUUU feeling that happens after you remove this little stone from your shoe.The idea is to continuously build the documentation using watch [2]watch -n 2 make htlmThis will update the generated documentation every 2 seconds. This is nice in itself and it leads me to discover that Epiphany automatically reload the page when it changes.[1] http://sphinx.pocoo.org/[2] http://linux.die.net/man/1/watch[3] http://projects.gnome.org/epiphany/ -
Hooking into django's login and logout - two approaches
Hooking into django's authentication system using two approaches: a custom authentication_backend and signals. -
Запускаем progopedia.com
Запускаем англоязычную версию Прогопедии — свободной энциклопедии языков программирования — progopedia.com. Сайт еще в стадии альфа-версии, не хватает описаний многих популярных языков программирования, движок определенно требует доработки — но для начала неплохо, я думаю. Сайт использует Django (естественно), Markdown (при помощи http://pypi.python.org/pypi/Markdown/) в качестве языка разметки, Pygments для подсветки синтаксиса, django-reversion для контроля версий, DISQUS и django-disqus для комментариев. Отзывы и комментарии приветствуются. Кто хочет присоединиться к progopedia.com в качестве редактора — присоединяйтесь :-) -
My Next Blog
I've been using this Blogspot powered blog for over a year now, and it is starting to get a little long in the tooth. Therefore I've been planning on moving to a new, shinny, blog of my own in the coming months. Specifically it's going to be my goal to get myself 100% migrated over my winter break. Therefore I've started building myself a list of features I want:Able to migrate all my old posts. This isn't going to be a huge deal, but it has to happen as I have quite a few posts I don't want to lose.Accepts restructured text. I'm sick of writing my posts in reST and then converting it into HTML for Blogspot.Pretty code highlighting.Disqus for comments. I don't want to have to deal with spam or anything else, let users post with Disqus and they can deal with all the trouble.Looks decent. Design is a huge weak point for me, so most of my time is going to be dedicated to this I think.Django powered!That's my pony list thus far. There's a good bet I'll use django-mingus since I've hear such good things about it, but for now I'm just dreaming of being able … -
Adding Javascript to contrib.admin inline fields
This recipe follows on from the last by adding Javascript to the inline fields of a model in the contrib.admin. -
Changes afoot at Django-NYC
Recently Justin Lilly and I have taken up the day-to-day running of the Django-NYC users group to take some load off its original founders, Loren Davie and Kevin Fricovsky. Loren and Kevin have done a great job of getting the group off the ground and building a community around Django in NYC. Unfortunately, as with most user groups, running [...] -
South – incredible easy migrations for Django
I’ve been hacking away at a side project for the past three or four weeks – got myself to internal milestone #2 this weekend, for which I’m really pleased. The very tail end of this milestone was deploying the code … Continue reading → -
Setup Python 2.6.4, mod_wsgi 2.6, and Django 1.1.1 on CentOS 5.3 (cPanel)
This is an update to my previous how-to Setup Python 2.5, mod_wsgi, and Django 1.0 on CentOS 5 (cPanel). The biggest reason why I chose to go with Python 2.5 at the time was because the MySQL Python (MySQLdb) package didn't support Python 2.6. The 1.2.3c1 release does so that roadblock is lifted. The instructions [...] Related posts:Setup Python 2.5, mod_wsgi, and Django 1.0 on CentOS 5 (cPanel) Ruby On Rails and SliceHost Part 1: Initial Setup Getting Started with Django and Python – First Impressions -
Why jQuery shouldn't be in the admin
This summer as a part of the Google Summer of Code program Zain Memon worked on improving the UI for Django's admin, specifically he integrated jQuery for various interface improvements. I am opposed to including jQuery in Django's admin, as far as I know I'm the only one. I should note that on a personal level I love jQuery, however I don't think that means it should be included in Django proper. I'm going to try to explain why I think it's a bad idea and possibly even convince you.The primary reason I'm opposed is because it lowers the pool of people who can contribute to developing Django's admin. I can hear the shouts from the audience, "jQuery makes Javascript easy, how can it LOWER the pool". By using jQuery we prevent people who know Javascript, but not jQuery from contributing to Django's admin. If we use more "raw" Javascript then anyone who knows jQuery should be able to contribute, as well as anyone who knows Mootools, or Dojo, or just vanilla Javascript. I'm sure there are some people who will say, "but it's possible to use jQuery without knowing Javascript", I submit to you that this is a bad … -
Setting up a django project with Cherokee, uWSGI and vitualenv (continued)
In my previous post [1] I have started to talk about this stack but I have avoided to mention that the django project was indeed encapsulated into a virtualenv. This brought a couple small quirks and questions to the surface. So I spent some times investigating and exchanging with the community behind uWSGI and cherokee in order to solve them. The enhancements I discuss here require that you use the tip of uWSGI [2] because some of them are new capability added in the past days or small improvements to my recipe of using these products.Before I start to dive into the enhancements let me sum up what we had to do in order to serve our WSGI project, in our case a django project.1> I had to add 2 configurations files : uwsgi.conf, django_wsgi.pyThe first one is an XML file where you define the PYTHONPATH and the mount point for your application, the second one is a python module where you define your WSGI configuration.2> I had to use the cherokee's wizard to create the appropriate configuration to serve my django app using uWSGI. This step add an "Information Sources" with the following settings in the interpreter section :/usr/local/bin/uwsgi … -
You need an editor
I’m supposed to be this expert on writing, right? So how come my previous articles have had so many errors? Simple: my blog doesn’t have an editor. That’s typical for a blog, but it’s unfortunately also typical of open source documentation: the vast majority of technical documentation doesn’t reach far beyond rough draft status. All good writers have a dirty little secret: they’re not really that good at writing. Their editors just make it seem that way. -
Django Golf Handicap Tracker
Django Handicap Tracker Screenshot This is the first Django application I ever built. It was started in the 0.96 days and I have since ported it to 1.0. It mostly works and now supports multiple users using the django-registration and django.contrib.auth module. I haven't done much work on it though. Eventually I will put it online for all to use. SVN path: http://svn.davidgrant.ca/repos/src/python/django_handicap Relative path in repository: /src/python/django_handicap SVN revision log View in Trac -
Django Golf Handicap Tracker
[img_assist|nid=361|title=Django Handicap Tracker Screenshot|desc=|link=popup|align=right|width=100|height=77] This is the first Django application I ever built. It was started in the 0.96 days and I have since ported it to 1.0. It mostly works and now supports multiple users using the django-registration and django.contrib.auth module. I haven't done much work on it though. Eventually I will put it online for all to use. Website: Golf Handicap tracker at github.com -
django-evolution aka orm pain part 2
Finally bit the bullet and tried out a new application to help me do the changes I needed to do on the db and boy am I glad I did. django-evolution is a joy to use. It's easy to install with no strange dependencies and it did everything out of the box as described. Initially somethings did trip me up such as the django-evolution's initialization actually looks only at the models.py and does not actually bother what is really in the db, as in say the models.py you define a field that is not actually in the db during the first 'python manage.py syncdb' to create the django-evolution table, it does not actually know that and will just carry on not knowing that there are discrepancies between the models.py and the actual db. After I figured that part out, it was easy. Just add the fields and their attributes, re-run an update script on my data and everything is done. Now my selects are much faster. Initially a 3k row db select was taking 50s and now using the caching functionality of select_related() it comes back in a blazing 4s. Ah here too initially I got tripped a bit as … -
Technical style
Now that I’ve discussed what kinds of technical documentation to write, I can move on to the question of how to actually develop a writing style that produces great technical documentation. Learn to write Unfortunately, there aren’t any shortcuts here. The best way to learn how to write great documentation is to first learn how to write (anything). There are some important differences between technical documentation and your average prose, but a solid foundation of good written communication skills is an irreplaceable prerequisite. -
When Django Fails? (A response)
I saw an article on reddit (or was in hacker news?) that asked the question: what happens when newbies make typos following the Rails tutorial, and how good of a job does Rails do at giving useful error messages? I decided it would be interesting to apply this same question to Django, and see what the results are. I didn't have the time to review the entire Django tutorial, so instead I'm going to make the same mistakes the author of that article did and see what the results are, I've only done the first few where the analogs in Django were clear.Mistake #1: Point a URL at a non-existent view:I pointed a URL at the view "django_fails.views.homme" when it should have been "home". Let's see what the error is: ViewDoesNotExist at / Tried homme in module django_fails.views. Error was: 'module' object has no attribute 'homme'So the exception name is definitely a good start, combined with the error text I think it's pretty clear that the view doesn't exist.Mistake #2: misspell url in the mapping fileInstead of doing url("^$" ...) I did urll: NameError at / name 'urll' is not definedThe error is a normal Python exception, which for a … -
Vancouver Sun Parking Tickets Website Screen Scraper
When the Vancouver Sun came out with their Vancouver parking tickets database I immediately had some burning questions, like, did the meter maids work on holidays? Do the work less in the evening than during the day? I found it difficult to answer these questions using their interface, so I decided to screen scrape all 1.6 million parking tickets in to my own MySQL database. This was a bit challenging as they made it difficult to screen scrape the data but eventually it could be done simply by first getting an AppKey, a hidden value inside the HTML source and then doing queries using that AppKey as a parameter. It took about a week to get all 1.6 million tickets downloaded. By using Django, it was easy to get them in to a database and view the results. Initially I just put all the data in to one table, then later I decided to normalize the data a bit which was interesting as I decided to do that in pure SQL which I hadn't done before. I did the scraping itself using a combination of BeautifulSoup, lxml, and mechanize. vancouver-parking-tickets project at GitHub MySQL SQL dump (42 MB) Here's some … -
Vancouver Sun Parking Tickets Website Screen Scraper
[img_assist|nid=367|title=|desc=|link=none|align=right|width=150|height=146] When the Vancouver Sun came out with their Vancouver parking tickets database I immediately had some burning questions, like, did the meter maids work on holidays? Do the work less in the evening than during the day? I found it difficult to answer these questions using their interface, so I decided to screen scrape all 1.6 million parking tickets in to my own MySQL database. This was a bit challenging as they made it difficult to screen scrape the data but eventually it could be done simply by first getting an AppKey, a hidden value inside the HTML source and then doing queries using that AppKey as a parameter. It took about a week to get all 1.6 million tickets downloaded. By using Django, it was easy to get them in to a database and view the results. Initially I just put all the data in to one table, then later I decided to normalize the data a bit which was interesting as I decided to do that in pure SQL which I hadn't done before. I did the scraping itself using a combination of BeautifulSoup, lxml, and mechanize. vancouver-parking-tickets project at GitHub MySQL SQL dump (42 MB) Here's … -
Django Recipes Application
Django Recipes Screenshot django-recipes at Google Code My mom was writing a family cookbook using Microsoft Word and I thought this was a bad idea for several reasons. At first I thought about using LaTeX to separate the style from the content a bit, then I thought about using XML, then I settled on a database as being the most generic to store recipe data. I quickly decided on using Django to create this cookbook framework because Python is probably my strongest language and it makes creating custom websites really easy. So far it includes: Most important models, Recipe, Ingredient, Direction, Category, Food. Very nice admin interface for creating recipes with inline ingredients and directions. Front-end: only a recipe_list and recipe_detail so far, but the recipe_detail has an experimental method of displaying recipes that is based on this LaTeX style: http://www.ctan.org/tex-archive/macros/latex/contrib/cooking/ (apparently based on style in a famous German cookbook by Dr. Oetker (Gromzik, J.; Reich, C.; Sander, C. (ed.): Dr. Oetker Schulkochbuch – Das Original. Ceres, Bielefeld, 1996.) Competitors/related projects: KRecipes - KDE-based desktop recipes software. Ben Collins-Sussman's effrecipes - Simple, but it works. Not under active development. Recipes on Rails - Ruby on Rails recipes site. Not open … -
Django Recipes Application
[img_assist|nid=362|title=Django Recipes Screenshot|desc=|link=popup|align=right|width=98|height=100] My mom was writing a family cookbook using Microsoft Word and I thought this was a bad idea for several reasons. At first I thought about using LaTeX to separate the style from the content a bit, then I thought about using XML, then I settled on a database as being the most generic to store recipe data. I quickly decided on using Django to create this cookbook framework because Python is probably my strongest language and it makes creating custom websites really easy. So far it includes: Most important models, Recipe, Ingredient, Direction, Category, Food. Very nice admin interface for creating recipes with inline ingredients and directions. Front-end: only a recipe_list and recipe_detail so far, but the recipe_detail has an experimental method of displaying recipes that is based on this LaTeX style: http://www.ctan.org/tex-archive/macros/latex/contrib/cooking/ (apparently based on style in a famous German cookbook by Dr. Oetker (Gromzik, J.; Reich, C.; Sander, C. (ed.): Dr. Oetker Schulkochbuch – Das Original. Ceres, Bielefeld, 1996.) Competitors/related projects: KRecipes - KDE-based desktop recipes software. Ben Collins-Sussman's effrecipes - Simple, but it works. Not under active development. Recipes on Rails - Ruby on Rails recipes site. Not open source as far as … -
Multiple Sites, Single Login with Django
One of the biggest barriers to entry on the web might be the "register -> check email -> login -> remember account info" paradigm. At work I recently developed a proof-of-concept app that allows a single login to work with multiple sites. How? iframe