Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Jutda - Django-powered Solution Provider
In my recent catchup blog post I mentioned in passing a few projects including Jutda and WhisperGifts. Now, I'd like to formally introduce the former of these (with the latter coming very soon now) When I'm not 'at work', I spend a significant amount of time working on other projects both independently and together with other talented developers. These days, all of these projects are powered by Django. Jutda is the glue that will pull these projects together under a single name. The name comes from the nearly-extinct Wagiman language, spoken by a small number of indigenous Australians. It means "to point" or "to show", which I've taken on as the ethos of my new company: We’re aiming to show the way to others, to make life easier through the use of elegant online solutions. The ultimate aim is to create simple solutions for everyday problems. No bells, no whistles, just beautiful outcomes for ugly problems. More information about Jutda can be seen on the About Jutda page, and in the initial blog post I published on the Jutda website. The first project that's been finished and published is WhisperGifts, about which I'll write more in a future blog post. … -
Jutda - Django-powered Solution Provider
In my recent catchup blog post I mentioned in passing a few projects including Jutda and WhisperGifts. Now, I'd like to formally introduce the former of these (with the latter coming very soon now) When I'm not 'at work', I spend a significant amount of time working on other projects … -
Generic search engine pinging for Django
The Django contrib sitemap framework provides a way to let Google know when your sitemap has been updated. It's simple enough to add Ask and Yahoo; until I can get a patch contributed, this module is an easy way to ping them all. -
Sitemap class for direct-to-template generic views
A simple way to include direct-to-template pages in the sitemap of your Django site. -
Django through Apache on Ubuntu
To: /etc/apache2/httpd.conf Add: <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE <project>.settings PythonDebug On PythonPath "['/parent', '/parent/project'] + sys.path" </Location> I found the instructions a bit confusing on the site. So I hope this clears up things a bit. My thought is they think the setup for live systems and where those files reside is [...] -
Installing Django from SVN and setting up django-registration (on Ubuntu)
Go to the shell and navigate to a directory that you want to leave the Django codebase. then enter the following code to check out the current codebase from Django: svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk Next you will need to make a symbolic link to the Django codebase: sudo ln -s `pwd`/django-trunk/django/ /usr/lib/python2.5/site-packages/django Link to django-admin, [...] -
Anatomy of a Python C Module
Writing Python modules in C is relatively easy. The main reason to do so is to increase performance over using Python code. I will demonstrate how to implement a Fibonacci Python function in C. -
Book news: Rough Cuts and Amazon
Just in time for Pycon, material from our new book is now available on the Safari "Rough Cuts" service. If you're a Safari subscriber, or decide to become one to get access to our draft chapters, please check it out and let us know what you think! Reader comments are incredibly important to us. We have a title now -- Python Web Development with Django -- and we're even listed on Amazon. Here's a summary blurb for those curious about how we are positioning the book: As a web developer, you want to program in a language that is powerful, clean, mature, and well-documented, and one that is equipped with a great standard library and a huge selection of high-quality third-party packages. You also want a web framework for that language--one with a vibrant, helpful community of users and developers, and one that is designed to function smoothly as an integrated stack, but whose components are loosely coupled so that you can make substitutions if circumstances require. In short, you want Python and you want Django. This book -- which includes a special "Practical Python for Django" chapter for those who need a language introduction or review -- is designed … -
Accepting NULL value in URL
Within my Django project I wanted to have a page within the site for example “/page”. For that site I want there to be an optional value the page can take. So any of the following examples are acceptable: “/page/1″, “/page/2″, “/page” There are two ways to do this. First way (which is probably the [...] -
Separating Development and Production Settings in Django
Django does not have a built-in way of having development only settings. Luckily for us, Django settings is nothing but a simple python module. This allows us to implement our own way of dealing with settings right in the settings.py file. On This Week in Django episode 4 (great podcast!), Michael Trier featured a Tip of the Week on how to implement development only settings. Since I like to have everything checked in to my Mercurial repository, I extended the code to allow local settings to exists on my production server without being loaded. The original version. 1 2 3 4 5[..] try: from local_settings import * except ImportError, exp: pass My version. 1 2 3 4 5 6 7[..] import socket if not socket.gethostname() == "omh.cc": try: from local_settings import * except ImportError, exp: pass It’s very simple. All it does is to check the host name and only import local_settings.py if host name is not “omh.cc”, which is the name of my server. -
Simplify Django's Free Comments Redirection
Django, with its battery included philosophy has several very nice features included. One of these cool features is the comments contrib application. In a few minutes, I was able to add commenting with Markdown highlighting to my blog. Not bad for a Django beginner. I opted to remove the annoying “Thanks for commenting” page and redirect directly back to the blog post. The Free Comments Wiki page explained how to do just that. However, it felt like way too much hassle, too much tinkering for a simple redirect. I live, uhm…, code by the motto: Less code is better code. Here’s my simplified approach. Add a line to your urls.py file overriding the default /comments/posted/ view. 1 2 3 4[...] ( r'^comments/posted/$', 'blog.views.comment_posted' ), ( r'^comments/', include( 'django.contrib.comments.urls.comments' ) ), [...] Make sure to add the urls.py line before the inclusion of comments. Now, create the comment_posted() method in your views.py file. 1 2 3 4 5 6 7 8 9 10 11 12 13from django.http import HttpResponseRedirect from mysite.blog.models import Post def comment_posted( request ): if request.GET['c']: comment_id, post_id = request.GET['c'].split( ':' ) post = Post.objects.get( pk=post_id ) if post: return HttpResponseRedirect( post.get_absolute_url() ) return HttpResponseRedirect( "/" ) That’s it. 10 lines of … -
Django Redirects (Updated)
This is a quick-n-dirty app to let you set up redirects on your Django site through the admin interface. (Updated to reflect my own oversight of django.contrib.redirects, which, er, does all this for you...) -
Django Redirects (Updated)
This is a quick-n-dirty app to let you set up redirects on your Django site through the admin interface. (Updated to reflect my own oversight of django.contrib.redirects, which, er, does all this for you...) -
Django Redirects (Updated)
This is a quick-n-dirty app to let you set up redirects on your Django site through the admin interface. (Updated to reflect my own oversight of django.contrib.redirects, which, er, does all this for you...) -
Django error notification with jabber
Django has a code error notifications mechanism when a view raises an exception. It will email the people in ADMIN tuple(settings documentation) in settings.py with the full exception information and displays the default 500.html template. This only happens when DEBUG=False in the settings.py. It's possible to set a handle that change this behavior with a handler500 variable in the root urls.py. So, we can easily write a simple view that sends an error notification to our jabber account. First of all, you need to install xmpppy and dnspython: $ easy_install xmpppy $ easy_install dnspython Add to settings.py the jabber parameters such as the jabber id, password, recipient, etc.: JABBER_ERROR_NOTIFICATION = True JABBER_ID = 'your_jabberid@jabberdomain.com' JABBER_PASSWORD = 'your_jabber_password' JABBER_RECIPIENT = 'recipient@jabberdomain.com' JABBER_ERROR_TEXT = 'An error occurred in "Project Name", please check your email.' Start a new app named errors or something else and add it to the INSTALLED_APPS tuple in the settings.py: python manage.py startapp errors Add a handler500 variable with the view in the root urls.py: handler500 = 'errors.views.server_error_jabber' Finally add the view in errors.views that sends a jabber notification and returns a 500 error page: from django.views.defaults import server_error from django.conf import settings import xmpp, time def server_error_jabber(request, template_name='500.html'): … -
Django error notification with jabber
Django has a code error notifications mechanism when a view raises an exception. It will email the people in ADMIN tuple(settings documentation) in settings.py with the full exception information and displays the default 500.html template. This only happens when DEBUG=False in the settings.py. It's possible to set a handle that change this behavior with a handler500 variable in the root urls.py. So, we can easily write a simple view that sends an error notification to our jabber account. First of all, you need to install xmpppy and dnspython: $ easy_install xmpppy $ easy_install dnspython Add to settings.py the jabber parameters such as the jabber id, password, recipient, etc.: JABBER_ERROR_NOTIFICATION = True JABBER_ID = 'your_jabberid@jabberdomain.com' JABBER_PASSWORD = 'your_jabber_password' JABBER_RECIPIENT = 'recipient@jabberdomain.com' JABBER_ERROR_TEXT = 'An error occurred in "Project Name", please check your email.' Start a new app named errors or something else and add it to the INSTALLED_APPS tuple in the settings.py: python manage.py startapp errors Add a handler500 variable with the view in the root urls.py: handler500 = 'errors.views.server_error_jabber' Finally add the view in errors.views that sends a jabber notification and returns a 500 error page: from django.views.defaults import server_error from django.conf import settings import xmpp, time def server_error_jabber(request, template_name='500.html'): … -
Exposing calendar events using iCalendar in Django
I recently wrote simple abstraction for exposing calendar events in Django as iCalendar feeds. It relies on vobject for managing the formatting of the calendar file, so you will need this if you want to try it out. It is available in Debian in the python-vobject package. Save this as a file somewhere in your project: import vobject from django.http import HttpResponse EVENT_ITEMS = ( ('uid', 'uid'), ('dtstart', 'start'), ('dtend', 'end'), ('summary', 'summary'), ('location', 'location'), ('last_modified', 'last_modified'), ('created', 'created'), ) class ICalendarFeed(object): def __call__(self, *args, **kwargs): cal = vobject.iCalendar() for item in self.items(): event = cal.add('vevent') for vkey, key in EVENT_ITEMS: value = getattr(self, 'item_' + key)(item) if value: event.add(vkey).value = value response = HttpResponse(cal.serialize()) response['Content-Type'] = 'text/calendar' return response def items(self): return [] def item_uid(self, item): pass def item_start(self, item): pass def item_end(self, item): pass def item_summary(self, item): return str(item) def item_location(self, item): pass def item_last_modified(self, item): pass def item_created(self, item): pass Now we need to couple this abstraction with a Django queryset. I placed this in a feeds.py in my application: from yourproject.path.icalendar import ICalendarFeed from yourproject.yourapp.models import SomeEvent class SomeEventCalendar(ICalendarFeed): def items(self): return SomeEvent.objects.all() def item_uid(self, item): return str(item.id) def item_start(self, item): return item.start def item_end(self, item): … -
Django Envy
Seriously, can the django and rails camps quit looking over each others' shoulders? The Liquid Templates project brings django's template language to rails. At least it will make transistioning from rails to django easier once that inevitably becomes fashionable. Post to Del.icio.us -
Django request logging
I'm a big believer in the utility of web application logging. Over the years I've almost always found it more useful than debuggers in diagnosing problems. The difficulty is achieving good logging. Here's a solution for Django projects that I'm pretty happy with. -
Automatic versioning of static content for Django sites
A standard performance tweak these days is to set long expiration dates on your site's static content. Here's the best way I've come up with to do that for my Django sites. -
A Django Auth Backend for Second Life
I've started hacking away at a personal project of mine around Second Life. More on that in the days to come, but I did want to share some code created last night while playing around with Second Life logins. I've worked up a Django authentication backend for authenticating users on a Django-based site against Second Life's login process. I've created a Google code project for the code, so cleverly named slauth.This is code of the "release early, release often" variety. There are no docs, no tests, not even a README. I just wanted to get this up while I had 5 minutes today. I welcome feedback, and I'm certain I will be working on this as the larger project evolves. I'm not even certain I'll use this in the final project. I feel uncomfortable taking username and password for another "site," but without a proper login API for site-to-site authentication, this seems to be the only viable route. This uses the same XMLRPC auth process of the Second Life viewer code, which seemed to legitimize it a little for me (since this is how third party viewers have to authenticate). It's certainly better than page scraping the response of the … -
ProfileMiddleware - sprawdź co zajmuje najwięcej czasu
Przy optymalizowaniu ważną rzeczą jest znalezienie miejsc które zajmują najwięcej czasu. Aby to zrobić używamy zmodyfikowanej wersji kodu znalezionego na djangosnippets. Pozwala on zobaczyć metody oraz moduły pożerające najwięcej zasobów. Poniżej wycinek wyników działania: ncalls ... -
Pobieranie tylko niektórych pól z bazy danych.
Niedawno na grupie dyskusyjnej Django pojawił się bardzo ciekawy patch. Entropy Hacker postanowił rozszerzyć dotychczasowe API Djangowego ORM'a o możliwość wyciągania tylko niektórych pól z bazy danych. Nie mówię oczywiście, że takie coś nie istniało. Metoda, która jest dostępna w... -
Special Ops for Django
I do a lot of hacking on django both at work and in my spare time. One of the things I like most about django is the built in admin. It's cheap, fast and reliable. But it doesn't always have the functionality you might want to add, and extending it isn't always the easiest thing to do. So much of what I do ends up being done in an ad hoc mode. It's only after performing a task a few times that you can really begin to get to the bottom of what is common and belongs in a framework, and what isn't. So when it came time to add some features to handle blog spam last week, I guess I finally had enough context to extend django's admin in a hopefully intelligent manner. What I've done is add what I'm calling admin actions to the standard admin mechanisms as defined in the models. The gist of it is that I've added a few new views and a single function decorator that you can use to unleash the additional functionality within the admin. ( BTW: you can get the diff to patch your instance from here. Just apply it to … -
Yet Another Python ORM
I’ve developed a Python ORM that is intended to be a lightweight, high-performance alternative to SQLObject, SQLAlchemy, the Django ORM, etc. Each of the preceding projects attempts to implement a comprehensive feature set. This ORM, however, is intended to be minimal, with as minimal of a configuration as required.