Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Conference available on Guidebook
Conference available on Guidebook Guidebook is a mobile app for your iPhone or Android phone and can store information of any conference, such as the schedule, sponsor information and a map of the venues. You need to have an internet connection to download the conference information but once it’s downloaded, you can access it offline. Handy when you are from abroad! Grab it here and look for the DjangoCon Europe 2011 guide once it’s installed. -
Updates to the django-utils task queue
After several months of running the task queue bundled with django-utils, I decided to re-evaluate certain aspects of the design. This post describes those changes. -
Wordpress to Django: Strategies Dealing with Wordpress Querystring URLs
Stable URLs are the foundation of valuable information on the web. As Tim Berners-Lee eloquently described it "Cool URIs Don't Change" and I thought I'd address a few strategies and code I'm using in MetaRho for maintaining stable URLs for content migrating from Wordpress. Wordpress Querystring URLs By default Wordpress uses querystrings for accessing content, passing the internal ID number of the post through the 'p' attribute like so... http://<domain name>/index.php?p=<post id> So for example calling post id 1 on mydomain.com would look like. http://www.mydomain.com/index.php?p=1 Since best practice for Cool URIs and in Django is to use real URLs instead of Querystrings this presents a small problem. The easiest solution I found is to simply implement a decorator in Django that I put on the default index view to watch for incoming WordPress querystring URLs and query some extra field on the model for blog posts that holds the original WordPress ID number. Note I do NOT try to maintain ID numbers between posts as the better practice is to keep these opaque from the user. I use the common strategy of keeping a one to many Model related to my posts to contain key value pairs for extra data. In … -
Django comparison grid
Comparison grid django application allows creating comparison grids, attaching arbitary content types to grids and editing grid content through django admin interface. If there is something you would like to see, get in touch – or just fork it on GitHub, add the feature (with docs and tests, preferably!) and send me a pull request: https://github.com/bmihelac/django-comparison-grid And here are two screenshots. Admin interface: Example output: -
Django Class-based Views
Since the release of Django 1.3, developers can choose to use class-based views in their web apps. Since the announcement of class-based views, there has been said a lot about them. As with all changes, there are pros and cons, people who are excited and people who are disappointed. I, and I guess a lot of people with me, are excited by the class-based views, but disappointed by the documentation Django gives with them. Time to try to clear things up.What do I like about Django's class-based views?Well, to start with: consistency. It might sound a bit lame, but I think it's a great thing that, following models and forms, views are now also part of the class-based club. I somehow always thought it was weird to write your forms and models in a class, but your views in a function. This weird feeling is now gone. Lucky me.Secondly: consistency. Again? Yes, again, because you can now force your own code to be more consistent, by using subclassing. You can, for example, write your own superclass view template and let all your other views subclass it.And last: Subclassing. I found it hard to find an example to make my point, … -
Django site permissions
I’m announcing Site permissions, django application that allows restricting access to objects based on which site they belong. Basic goal is to allow restrict managing site content to users and groups in django admin interface. Site permissions works on and depends on django-guardian. Source code and example app is available on githib: https://github.com/bmihelac/django-site-permissions -
Handy mod_wsgi process names
One of the reasons I started experimenting with gunicorn instead of mod_wsgi was that it would help me identify the sites when looking at cpu/memory usage with top. With standard apache+mod_wsgi, you only get line upon line of /usr/sbin/apache2 -k start with no indication of which site it actually is. Turns out mod_wsgi can do that just fine, too! I got a comment on my gunicorn blogpost from Diederik v/d Boor that told me about mod_wsgi's display-name option. It was right there in mod_wsgi's WSGIDaemonProcess documentation but I completely overlooked it. What I did was to add a display-name like this: WSGIDaemonProcess mysite display-name=mysite_wsgi user=xyz group=xyz In top you might have to press c to view the full commandline for every top line. (Tip: press W to write the top config to disk to persist the change). See this picture. It shows a couple of not-yet converted wsgi sites with the unhelpful /user/sbin/apache2 name and a couple with the sitename with _wsgi in it. -
Leverage browser caching in Django and Lighttpd
An easy optimisation that greatly improves your website’s speed is to leverage browser caching through appropriate HTTP response headers for static files (CSS, images, JavaScript, etc.). My favourite technique is to set long expiration timestamps and then to force browsers to reload updated static content by a slight change in the file path. This technique is fairly easy to set up in Django and Lighttpd. -
Single simple view for Django form processing
I always feel a bit dissatisfied with the amount of code I have to put in to process forms in Django views. Like most python developers it feels like I've gotten too complex it if takes me more than 5 or 6 lines of code to do something. Previously I had coded seperate create and update views for form processing, partially this was to better control permissions but also because of the differences in dealing with bound and unbound forms as well as model instances. This is my first stab at implementing that simple logic based on several examples I've seen out there in other blogs. @login_required def post_edit(request, id=None): """ Handles creating or updating of individual blog posts. :parm request: request object being sent to the view. :param id: post id, defaults to None if new post. """ instance = None if id: instance = get_object_or_404(Post, id=id) title = "Create New Post" if instance: title = "Editing Post" # Create the form as needed. form = PostForm(request.POST or None, instance=instance) # Didn't work for me unles I passed k,v pair in instance. # Save the edited form if needed if request.method == 'POST' and form.is_valid(): # Validate and … -
I don’t like Django class-based generic views.
Django had function-based generic views through version 1.25. They were replaced in version 1.3 by class-based generic views. Some caveats: I’m not the sharpest knife in the drawer. I’m not FSM’s gift to web development. I have a lot of experience with the function-based generic views, and little experience with the class-based ones. (Because they’re new. Duh.) From yesterday’s experience, the new generic views use a very powerful but excessively complicated abstraction. I can only symptomatically describe the problem and I don’t have a good answer, but this is my blog so I’m going to bitch about it. If you don’t agree then move along, these aren’t the droids you’re looking for. My task was simple: Code a, “display detail about an object,” page. The object is a db table row. That’s all. After two hours, I wanted to stab my eyes with live yellow jackets. I wanted this page accessible to only logged-in users, so I needed to override as_view() and use @login_required(). I also needed one of our decorators to verify that the user owned the db row. And, of course, I had to pass the db row object (from a Foobar.objects.get(yadda yadda yadda) call) to the as_view(). … -
Reading Site Domain into Django Templates
There are a number of great new features in Django 1.3 for template developers. Not the least of which is the addition of the STATIC_URL attribute in settings.py to help with referencing static media. I found when trying to integrate social media linking in blog posts however that there wasn't a good way to pull the entire site domain into a URL without hard coding into the template. Something that makes and descent Django developer shiver. The easiest way around this is to use the .get_current() method of the Site model and access that via a custom template tag in your templates. The code itself is very simple: from django import template from django.contrib.sites.models import Site register = template.Library() @register.simple_tag def sitedomain(): '''Returns the URL of the default site.''' try: return Site.objects.get_current().domain except Site.DoesNotExist: return None This makes it pretty easy to call in your template. I was able to use it to forward complete URLs onto some javascript functions that provides social linking in posts. -
New handy blog from a colleague
One of my colleagues regularly sends out an email to us with a couple of nice javascript or python packages he noticed online. Or handy websites. I like getting those, as it is an extra source of input and inspiration. Since two days or so he's got a blog. And he's apparently decided to do the company-internal-email thingy on his blog, too. Lots of potential to be a useful resource, I'd say. Two examples: Literate programming. Interactivity in mapping apps. Check it out at http://weblog.nyholt.nl . -
Two useful enhancements for Django Debug Toolbar
Sometimes on my work I experience two typical issues: first one is that on unknown projects I don't know what objects was changes, how much objects was changed and what is deleted. To find out what's going on the current page(s) I have to study code of views, internal methods etc. Sometimes it's really pain in the ass, for example if I work on satchmo-based projects.Another typical issue is hard way to keep valid HTML during long-term development. I don't want to add plugins to my browser which will validate my html. But I still need to develop clean and transparent HTML code. So I made decision to develop additional HTML Validator panel for Django Debug Toolbar.Past month I've done two panels (screenshots below):State Debug Panel – debug_toolbar.panels.state.StateDebugPanelHTML Validator Debug Panel – debug_toolbar.panels.htmlvalidator.HTMLValidationDebugPanelAll of the code was merged with current master of django-debug-panel and available on github -
Caching web sites and web applications…
…Why, Where, What and How of caching web sites Basics of web page load: Every time when you open an webpage this results in a series of requests and responses between the client(your browser) and the web server that hosts the requested sites(most of the times this includes more the one servers). Each request tells [...] -
Python on Android, Django Unit Testing at OPAG
Ottawa Python Authors Group meeting tomorrow Thursday May 26 at 8p.m. Best of all it's not me talking this time! Hope you can make it out. -
A REST wankery question
Consider a simple photo storage service as an API. Users can only interact with the API if they’ve got an account. Let’s say authorization happens over HTTP Basic. Given that, would you use URIs like /photos and /photos/{id} (as a photo list and photo detail resource, respectively)? What’s weird about those URIs is that my /photos is a different list of photos than your /photos – in other words, the resource represented depends on the information in the Authorization header. -
Gunicorn zero-length bug fixed
Two weeks ago I wrote about a zero-length bug I encountered with gunicorn when running it under apache in certain cases and when using internet explorer. Corner case, but still. With some apache tweaking I managed to work around it (or solve it). I submitted a bug report suggesting a small doc update for this corner case and got a quick reply from the author asking me to try out the most recent release, as that apparently contained an fix for "chunked encoding". I hooked 0.12.2 up into my site instead of the 0.12.1 that I was using and yes, it fixes it! So hurray for open source and responsive authors! -
Django Models Mixins
One thing I've been experimenting with is model Mixins. For example, the aim is to create small abstract classes that are each focused around a particular function. These abstract classes can then be added to arbitrary models to apply those functions to models as desired.For example, say I define a RatingsFields abstract class and a TrackingFields abstract class. These abstract classes can be mixed into any other model that we wish to add rating or tracking functionality to. core/mixins.pyfrom djangoratings.fields import RatingField # 3rd party moduleclass RatingFields(models.Model): rating = RatingField(range=5) # 5 possible rating values, 1-5 class Meta: abstract = True class TrackingFields(models.Model): deleted_on = models.DateTimeField(blank=True, null=True) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Meta: abstract = True Since we applied the abstract classes to the Post model below, the model now has rating and tracking capabilities. This is useful to help simplify code where a lot of models share fields or methods with the same function.myapp/models.pyfrom core import mixins as core_mixinsclass Post(core_mixins.TrackingFields, core_mixins.RatingFields): name = models.CharField(max_length=128) slug = models.SlugField(max_length=128) ...Comments welcome.Joe -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por Valder
Guilherme, o download via git/svn por FTP é impossível. O que vc pode fazer é fazer isso em sua máquina e mandar por ftp para o servidor da UOL. O que dá para fazer e testar uma estrutura de diretórios diferentes da do tutorial. Algo como: public_html/Django public_html/meu_projeto public_html/.htaccess Ai no .htaccess vc manda o PYTHONPATH para o public_html/Django;public_html/meu_projeto Não fiz os testes, mas acho que é possível. Já que o apache não vai ligar para os exports, ele apenas enxerga as informações do .htaccess SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE meu_projeto.settings PythonInterpreter meu_projeto PythonOption django.root /meu_projeto PythonDebug On PythonPath "['/home/valdergall/public_html','/home/valdergall/public_html/Django'] + sys.path" Acho que se vc jogar o diretório que contém do diretório django que fica dentro do Django direto no public_html nem precisa ter 2 caminhos no python path. Mas eu não tenho certeza se vai funcionar. Outra opção é usar o virtualenv para o seu próprio ambiente de projeto e jogar todo o envproject no public_html. -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por Guilherme
E pra quem tem serivço de revenda e não tem acesso via ssh para fazer o download via trunk/git/svn o que fazemos? Já tentei o processo que o suporte recomendou copiar a pasta do projeto para uma pasta (public_html/meuprojeto) e colocar dentro dela o arquivo .htaccess isso está certo? não deu certo comigo. Tem outra solução? -
Audio recording in Django apps with flvar
flvar is a flash applet working with a media server and allows users to record audio clips on a website using it. To use it in a Django project you need to setup the media server like Red5, and map some hardcoded paths in flvar recorder to Django views and templates. -
Getting Django to work with uWSGI on Cherokee
* Installing uWSGI * Creating uwsgi.conf file /home/emilian/springmerchant dev.django_wsgi * -
CouchDB + Django + Couchdbkit
CouchDB + Django + Couchdbkit -
CouchDB + Django + Couchdbkit
Just some notes for future use. Couchdbkit: Searching by key: Document.view('document/all', key='') -
The state of python and the web - Armin Ronacher (PyGrunn conference)
Armin's a founding member of the pocoo team with projects like jinja2, werkzeug, sphinx and so. Python 3 is the elephant in the room that nobody's talking about. There's a lot of python 2 code and porting is turning out to be harder than expected. Some recent python developments: Unladen swallow is "resting". Development stopped. It was the number one hope to make python faster. Python 3.2 got released. Python's packaging is being worked on a lot. Pypy turns out to be quite fast nowadays. Really really fast. What's pypy? It is python written in python. Well, in "restricted python", which can be translated to C automatically. It is 3.7 till 40 times faster than regular cpython!!! Things that will work? Django, flask, pyglet, twisted, sqlite, ctypes and so on. A problem with pypy is that there's only experimental support for the python C API. And C-level extensions will always be slow. And there is no reference counting, so you need (for instance) to close files yourself. But, in summary, python 3 is where all the new language development is happening. What does python 3 mean? Unicode cleanup. All text-like things are either unicode text or a binary blob. The …