Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django Pattern for Reporting Errors/Messages in Views
I've tried tried to find a decent way to design my Django views so that I can smoothly report errors to users. The errors that I am concerned about are errors that users encounter if they are preforming actions that are typically NOT normally encountered through normal use of the user interface. For example, if users try to directly access a URL of an object that doesn't exist, if they post incorrect values to a URL, or a required value doesn't exist in the user's session. In a utility module, I create a message class that I to store message information. While view processing is taking place, if an error takes place, this class will be used to store the error title, text, and "back" url link. core/utils.pyclass UserMessage(): def __init__(self, title="", text=[], url=None): self.title = title self.text = text if hasattr(text, '__iter__') else [text] self.url = url The view continually checks for the existance of a UserMessage instance. (In the example below, "message" variable is an instance of UserMessage) If an error condition occurs, part of the handing will be to create a new UserMessage, and the view renders an error page using the template defined by message_template_name and … -
Using jQuery templating ICanHaz.js with Django
When working on a Django project with an important part of the user experience based on AJAX, you better use a frontend templating language. The same way Django has a templating language that we use to populate values easing your coder’s life, jQuery has client side alternatives. One of these plugins and my personal favorite is ICanHaz.js created by @HenrikJoreteg. It’s only 4.4 Kb. ICanHaz.js syntax will be very familiar to Django devs, because a variable is defined using double curly brackets {{ variable }}. But I will not enter into details, the project has very easy to follow setup instructions and code examples. When people start using ICanHaz.js in their Django templates, they have a very hard first time trying to get it to work. The problem is simple, Django and ICanHaz.js share the same variable definition, so Django interprets the script templates, breaking them. When I found this out, I looked over the Internet until I found a fix by Eric Florenzano (@ericflo). He coded a templatetag called verbatim, that avoids that Django interprets all content within the block tag. He published it as a gist in Github. You simply have to put this within one of your … -
Python Monads - new approach
-
Python Monads - new approach
I wondered if monads (I probably mean do-syntax) could be implemented in Python. I even googled, but the results1 were not good: in particular, the implementation I found couldn’t work with List monad. The List monad is something I really like (it helps with Project Euler, for example), and I was also able to implement the awesome Probability monad2. So my implementation maybe of some interest. There are other notable things which I liked, for example a lambda-based syntax to use needed (and only needed) bound variables. I must admit that I’m not sure these are exactly monads as in Haskell, but they seem to resemble the do-notation. I like do-notation, call me n00b if you want to. I even managed to use <- as an operator, and don’t ask me how. Okay, take a look: from monads import do, List, Maybe, Probability, mreturn, Var, guard # this is a List monad: l2 = do( Var('a') <- List(lambda: [1, 2, 3]), Var('b') <- List(lambda a: [a + 1, a + 9, a * 40]), Var('c') <- List(lambda a: xrange(a + 5)), guard(lambda b: b < 30), mreturn(lambda b, c: (b, c)) ) print l2.run() # this is Maybe, and it's, … -
AJAX Form Submission in Django
Here is a simple example of using the jQuery javascript framework to hijack and submit a Django form. -
Free Professional Web Development
I'm pleased to announce my immediate availability for some freelance Web development projects. Lately, I've been quite swamped with a very awesome project at my day job. Many things had to be put on hold as a result of that project. However, it looks like the worst is now behind me, and I find myself with much more free time than before! As such, I'm opening the doors to any and all (except full-time, because I love my day job) Web development opportunities. I guarantee absolute satisfaction and reliable, efficient Web sites, and I deliver quickly. All you need to do is provide the requirements for your project in the comments section of this article. I'll pump out at the very least a proof of concept that becomes your property (free of charge), no questions asked. You will not be disappointed. Use this as an opportunity 1) to get free stuff and 2) to test your requirements-gathering/communicating skills. Let the battle begin! -
Announcing Garbaginator!
While working on Packaginator at the PyCon 2011 sprints we discovered some serious issues in the way that Django handles garbage collection. After a huge amount of work, we managed to isolate and fix the problem. This 'fix', as it were, was only possible by doing a very sophisticated 'hack' of critical internal components of the Django Web Application framework. We also discovered that similar issues occurred in other existing Python application frameworks such as Pyramid, Flask, Web.py, Web2Py, Grok, Twisted, Tornado, Google App Engine, and Rails.Since then the Packaginator community has been fiercely debating what we should do with our newly created set of hacks. After a lot of arguments going both ways we've decided to come up with our own application framework and release it to the world under the GPL license.This brand new application framework ignores the lessons learned from all the other Python frameworks and embraces the cutting edge concept of Not-Invented-Here. It focuses less on features and enhancements over existing systems and much, much more on the critical concept of formal Garbage handling.Some of the critical modules include:RubberGloves (for handling dirty objects)Django-GarbaginatorFlask-RecyclingPyramid-GarbaginatorWeb.2.py Garbaginator Bridgerator ('cause people always get Web2Py and web.py confused with each other … -
Subprocess Bug on Windows?
The bug appears to be with 'Fabric' and not subprocess, skip to comments for an explanation I recently looked into using Fabric to automate my Django deployments after reading about the benefits in James Bennett's excellent 'Practical Django Projects'. Whilst following the tutorial on the website I encountered a ... -
Djangocon.eu is gearing up!
2011's djangocon.eu is really gearing up. I like the looks of the fresh website. 6/7/8 June in Amsterdam, here I come! And the sprints afterwards, too, of course. I'm on the conference organizers' mailing list and word is that already half the available tickets are gone! So get yours while they're still available. Early-bird discount pricing is valid till this Friday, btw. Some good things I want to say about the conference location: Amsterdam is incredibly accessible. Every big airline flies to Schiphol airport (Amsterdam's airport). And the TGV/Thalys/ICE high speed trains are there, too. I've seen the conference center itself (pakhuis de zwijger) on the inside two times at a Dutch plone user group day. Good building for a conference, to be sure. I haven't seen the sprint location on the inside, but surely nothing beats a medieval city gate building as a sprint location :-) On the bad side: Amsterdam must by a city of robber barons if those hotels are that expensive. At least the official conference ones are expensive in my opinion. I'm sure there are way cheaper ones (but I don't know which ones). Anyway, I live 45 km away so my company probably won't … -
Djangocon.eu is gearing up!
2011's djangocon.eu is really gearing up. I like the looks of the fresh website. 6/7/8 June in Amsterdam, here I come! And the sprints afterwards, too, of course. I'm on the conference organizers' mailing list and word is that already half the available tickets are gone! So get yours while they're still available. Early-bird discount pricing is valid till this Friday, btw. Some good things I want to say about the conference location: Amsterdam is incredibly accessible. Every big airline flies to Schiphol airport (Amsterdam's airport). And the TGV/Thalys/ICE high speed trains are there, too. I've seen the conference center itself (pakhuis de zwijger) on the inside two times at a Dutch plone user group day. Good building for a conference, to be sure. I haven't seen the sprint location on the inside, but surely nothing beats a medieval city gate building as a sprint location :-) On the bad side: Amsterdam must by a city of robber barons if those hotels are that expensive. At least the official conference ones are expensive in my opinion. I'm sure there are way cheaper ones (but I don't know which ones). Anyway, I live 45 km away so my company probably won't … -
Petites apps … petites mais costaudes
Pour ce mois de mars, je vais parler non pas d'une seule mais de deux petites apps. Deux apps parce que les apps sont tellement petites que l'on va m'accuser de tirer au flanc si je ne parle que de l'une d'entre elles. Mais que d'un autre cotés, ce n'est pas parce qu'elles sont ... -
Announcement: Dates for Django Training, London
After delivering some successful django training for Bangor University in January, I’ve finally got around to setting up my own course. This will be a 2 day introduction to Django for programmers, and will take place on the 17th and 18th May 2011 at City University, London. The course assumes that you can already program [...] -
Django Pattern For Model Permissions
I think I've found an interesting way to set up a permissions system in Django. This system allows you to specify granular permissions on specific object instances and is template friendly. Setup The Permissions InfrastructureFirst, you create an "abstract" Permissions class that models will use as a permissions base class. This base permissions class sets up simple caching for the permissions and creates some common methods to be used by all permissions objects. The current_user represents the logged in that you want to check permissions for a particular object.Notice the use of threadlocals here. If current_user is not supplied in the constructor, the class will try to lookup the current_user from a variable by the threadlocals middleware (see below). Be warned, however, some people don't seem to like the threadlocals approach. To be honest, I'm still trying to evaluate the pluses and minuses, but it sure makes certain things in the templates easier. Comments are welcome. core/permissions.pyfrom core.middleware import threadlocals class Permissions(object): def __init__(self, obj, current_user=False): if not current_user: current_user=threadlocals.get_current_user() if not current_user: current_user = None self.current_user = current_user self.obj = obj self.cache = {} def clear_cache(self, key=None): if key: try: del self.cache[key] except KeyError: pass else: self.cache.clear() def get_current_user(self): … -
Satchmo Status Update
Despite the lack of activity on the satchmo site, there is still plenty of work going on to make Satchmo more stable, feature rich and generally all around better. -
DjangoAstuce : masquer certains champs des settings dans la vue de Debug
Par défaut, la vue de DEBUG affiche toutes les settings. Heureusement pour nous, gentils petits djangonautes, les password des BD mais aussi le password du user emails sont remplacés par des belles petites ***.   Mais comment faire pour masquer d'autre champs ? Comme des champs de KEY d'API ou de password divers ? Parce qu'après ... -
Internet Explorer, jQuery, AJAX and HTML5…
… or how “invalid” HTML can break your JavaScript without a trace The problem: A few days ago I had the following case. A script that I wrote was working everywhere except in the Internet Explorer(IE) 8 and 7. To be honest I don`t remember the exact error message but when I use the built-in [...] -
Comentário sobre configurando um projeto django no uol host – terceira parte por Valder
Thiago, blz ? Mas, no caso o que vc está fazendo errado é que o .htaccess deve ficar sempre uma pasta abaixo do projeto Django ('settings.py') Assim vc vai apontar o PYTHONPATH para uma pasta abaixo do projeto, no local onde está o .htaccess. Ai ele aceita ter vários projetos de django na mesma hospedagem. Sendo assim o domínio do seu cliente iria para www.valdergallo.com.br/thiago/ onde teriamos os seguintes diretórios: public_html thiago .htaccess site_django settings.py myapp media_django Lembrando que quem vai servir os seus arquivos estáticos é o próprio django. Então o caminho dos mesmos deve ser definido no settings.py Já tinha respondido isso em outro post. Porém acho que ficou meio vago. Espero que assim fique melhor. Abraço -
Django Authentication using an Email Address
A custom authentication backend which allows a user to login using their email address in Django. -
Issues using django-compress and django.contrib.staticfiles from django 1.3
There is no way to use both django-compress and django.contrib.staticilfes from new django 1.3. MEDIA_URL and MEDIA_ROOT hardcoded into django-compress utility functions so here ismy fork of django-compress on github with fix.I've added two new settings COMPRESS_URL and COMPRESS_ROOT which points by default to MEDIA_URL and MEDIA_ROOT respectively for backward compatibility.django-compress is extremely useful tool which provide possibility to organize your JavaScript and CSS files around your project. Also there is a couple of useful features like support of YUI compressor and building of bunch of JavaScript or CSS files into one.Read more about django-compress -
direct_to_template generic view class-based replacement for django 1.3
I was in love with direct_to_template shortcut from django.views.generic.simpleUpdate: It was my lack of attention to the docs. new render shortcut do the same thing as code belowIt's extremely useful to use direct_to_template instead of render_to_response because there is no necessary to put RequestContext to direct_to_template shourcut. But now it's deprecated so I decided to replace it with small class-based view which do same thing as old direct_to_template but – without restriction of new TemplateView where is no way to put extra context.from django.views.generic.base import TemplateResponseMixinfrom django.template import RequestContextclass RenderTemplate(TemplateResponseMixin): """django 1.3+ Class-Based replacement for django.views.generic.simple.direct_to_template Usage: context = {} return RenderTemplate.view(context, \ request=request, template_name="main.html") """ @classmethod def view(cls, context, render_args={}, **initkwargs): obj = cls() for key, val in initkwargs.iteritems(): setattr(obj, key, val) return obj.render_to_response(context, **render_args) def render_to_response(self, context, **kwargs): return super(RenderTemplate, self)\ .render_to_response(RequestContext(self.request, \ context), **kwargs) -
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/: -
Deploying to ep.io with secret stuff
hej -
Deploying to ep.io with secret stuff
hej -
Django Dynamically Generated Images with Cairo
It is fairly simple to dynamically generate images in your Django views using the Cairo 2D graphics library. -
2009 Django Dash Complete
The 2009 Django Dash is done. The site (http://alt.djangodash.com/) has the full commit logs and some interesting stats (overall, per team, per dasher). I'll do a better post-mortem tomorrow. Congratulations to all who participated and hope to see you next year!