background preloader

Django

Facebook Twitter

Memcached

Dreamhost. Django-apps. Signals. Review. Manytomany. Oembed. Be careful with your URL patterns. Tonight in the Django IRC channel, someone stumbled across a seemingly-odd error when trying to use a generic view: TypeError: object_list() got multiple values for keyword argument 'queryset' The problem turned out to be the URL pattern which was routing to the generic view. Consider a simple example, as might be found in a weblog application: The idea here is that either of two different URLs — index/ or weblog/ — should route to the object_list generic view and display a list of entries, and at first glance this looks all right; it’s even somewhat clever in using the regular expression to handle two potential URLs instead of having two full patterns which essentially do the same thing. But it’ll actually raise the TypeError listed above.

The reason for this is that parentheses in a regular expression also capture the values they match. If you find yourself needing to use this regex feature without the risk of accidentally screwing up your view’s arguments, use non-matching parentheses. Iraniblog » Running long processes in Django. My original issue was that I had this piece of code in my Django project that was taking way too long to run, sometimes even leading to a load time out. The particular situation happens very infrequently (at most once a week), so it was just a matter of getting the process to run successfully.

Along the way, though, I learned a lot about spawning processes, distributed computing, and the different options we have in the Python community. The different approaches are just ways to get the processing to be done outside the Django process, of course. cron and queue cron I will first start with the recommended process of taking care of this issue. You can setup a cron job to run some code that checks every minute to see if there’s anything to process and then run the appropriate code. Cron jobs are pretty simple to setup and pretty effective. Django-queue-service The cron part of this solution takes care of when the processing happens, but what handles why it happens?

Code from my Pyro file: Define css class in django Forms. SaaS with Django and PostgreSQL - tidbids's posterous. Irrational Exuberance. A response to Dropping Django — The Uswaretech Blog - Django Web Development. By : Shabda Raaj Brandon Bloom yesterday wrote an interesting post titled dropping Django. Despite a lot of hand waving(We needed a pragmatic template language to replace Django's idealistic one.), it raises some valid questions, so here is a solution to some of them. No support for hierarchical url creation. The simplest representation of nested urls I can think of is a nested tuple.

Lets represent, the urls for a simple app by, >>> tree_urls = ('', 'list',... ('edit/', 'edit', ('auto/', 'edit_auto')),... Guess what, urls.py is just a python module which excepts a variable names urlpatterns. Which means it is very easy to write a function which converts this nested structure to flat, structure. With this you can use hierarchical urls in urls.py as, #All of urls.pytree_urls = ('', 'list', ('edit/', 'edit', ('auto/', 'edit_auto')), ('^add/', 'add'), ('delete/', 'delete', ('delete/', 'delete_hard')) )flat_urls = generate_flat_urls(tree_urls)urlpatterns = patterns('app.views',**flat_urls)

What I don’t like about Python « Luke Palmer. At work I’ve had the pleasure of programming a preprocessor for our code base. It just takes an XML specification of structures and generates Lua accessors, serializers, etc. I did it in Python, mostly because our developers already have to have Python installed to use the test suite. This has given me a chance to get more familiar with Python as a programming language for doing real things (previously I knew enough to make minor modifications to code; basic block syntax, variable model). First, I love the “usual” syntax. I think Python excels where other languages are mediocre is in communicating to the compiler and the user simultaneously, clearly, what is going on.

However, that strength of Python is also a weakness. I think one of the biggest reasons why it is not possible to express code at this level is the lack of a multi-statement lambda. My use case code could look like this (using Ruby-style parenless block passing): It gets worse when you want composability, though. Thomas Brox Røst. Speed matters. When Google tried adding 20 additional results to their search pages, traffic dropped by 20%. The reason? Page generation took an extra .5 seconds. This article will show how Eventseer utilizes an often overlooked way of improving the responsiveness of a web application: Pre-generating and serving static files instead of dynamic pages. The tools I will be using include Django, Django StaticGenerator, Django Queue Service and Amazon Web Services (AWS). Interfacing with AWS from Python is best done with the boto library, but that will not be covered in this article.

Some knowledge of Django and AWS is helpful but not required. About the siteEventseer is an academic event tracker that at the time of writing contains some 8,000 event listings. On the backend we use Django with a PostgreSQL database, hidden behind a lighttpd/FastCGI web server. The problemAs traffic grew, Eventseer was becoming slower.

Traffic analysis showed the average server load to be consistently high. Hacker News | Ask YC: What are some of the Python blogs you read?