Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Angelo Dini is a core developer
Angelo Dini is a core developer -
Using the Django-Pagination app in Django 1.3
Like many Djangonaughts I use django-pagination as my primary means to page results on lists pages and between the differences on the original Google project page(1.0.5 is the last downloadable version), what appears to be the same project migrated to GitHub and the PyPi (1.0.7 is the pip install version) site for the project, things can get confusing. I'm probably the only person confused by this but it appear that the GitHub site is the most up to date and it appears to be in sync with the pip install version. Life signs overall are dubious on the project though with no updates having come since early 2010 and several (what seem to be) reasonable pull requests sitting in the project queue. One gotcha I wanted to point out in the PyPI readme file is the directions for TEMPLATE_CONTEXT_PROCESSORS: According to the project documentation, in settings.py you should set: TEMPLATE_CONTEXT_PROCESSORS= ( "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.request" ) This can cause some problems in Django 1.3 however since the default TEMPLATE_CONTEXT_PROCESSORS have changed, in particular to support the new features for serving static media. So to include for pagination to work and to keep the default template context processors you should instead set: … -
Free bikes
Free bikes The City of Amsterdam is offering participants of DjangoCon a free bike for the duration of the conference. You can collect a voucher on monday during lunch. -
Test static resources in Django tests
At Mozilla we use jingo-minify to bundle static resources such as .js and .css files. It's not a perfect solution but it's got some great benefits. One of them is that you need to know exactly which static resources you need in a template and because things are bundled you don't need to care too much about what files it originally consisted of. For example "jquery-1.6.2.js" + "common.js" + "jquery.cookies.js" can become "bundles/core.js" A drawback of this is if you forget to compress and prepare all assets (using the compress_assets management command in jingo-minify) is that you break your site with missing static resources. So how to test for this?[367 more words] -
Test static resources in Django tests
At Mozilla we use jingo-minify to bundle static resources such as .js and .css files. It's not a perfect solution but it's got some great benefits. One of them is that you need to know exactly which static resources you need in a template and because things are bundled you don't need to care too much about what files it originally consisted of. For example "jquery-1.6.2.js" + "common.js" + "jquery.cookies.js" can become "bundles/core.js" A drawback of this is if you forget to compress and prepare all assets (using the compress_assets management command in jingo-minify) is that you break your site with missing static resources. So how to test for this?[367 more words] -
Test static resources in Django tests
At Mozilla we use jingo-minify to bundle static resources such as .js and .css files. It's not a perfect solution but it's got some great benefits. One of them is that you need to know exactly which static resources you need in a template and because things are bundled you don't need to care too much about what files it originally consisted of. For example "jquery-1.6.2.js" + "common.js" + "jquery.cookies.js" can become "bundles/core.js" A drawback of this is if you forget to compress and prepare all assets (using the compress_assets management command in jingo-minify) is that you break your site with missing static resources. So how to test for this?[367 more words] -
Test static resources in Django tests
At Mozilla we use jingo-minify to bundle static resources such as .js and .css files. It's not a perfect solution but it's got some great benefits. One of them is that you need to know exactly which static resources you need in a template and because things are bundled you don't need to care too much about what files it originally consisted of. For example "jquery-1.6.2.js" + "common.js" + "jquery.cookies.js" can become "bundles/core.js" A drawback of this is if you forget to compress and prepare all assets (using the compress_assets management command in jingo-minify) is that you break your site with missing static resources. So how to test for this?[367 more words] -
JavaScript Libraries Statistics
-
Django models ForeignKey and custom admin filters…
… or how to limit dynamic foreign key choices in both edit drop-down and admin filter. The problem: Having a foreign key between models in django is really simple. For example: Unfortunately in the real live the choices allowed for the connection are frequently limited by some application logic e.g. you may add answers only [...] -
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.