Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Use double quotes for {% url %} on Django
I recently commented about using the right quotes with Python and simplejson and today I found a similar issue with Django. It happens when using the {% url %} tag on the template system in Django 1.0. {% url %} helps you to avoid hardcoding links and relies on naming your url patterns. Let's suppose we have a url like this in our URLConf: url(r'^add/chatroom/(?P\w+)$', 'myapp_chatroom_add', name='myapp_chatroom_add'), Now you could insert {% url %} in your template to get the url for a link: {% url myapp_chatroom_add chatroom_data="abc" %} Notice I'm passing the string "abc" using double quotes as the chatroom_data parameter. And here's the important part, these two won't work: {% url myapp_chatroom_add chatroom_data=abc %} which does not use quotes at all, or this one: {% url myapp_chatroom_add chatroom_data='abc' %} which uses single quotes. The errors may vary depending on how your code works but the fact is to remember that when passing string based parameters to {% url %} you need to always use double quotes. If you're using numbers you could use either no quotes or double quotes. Single quotes will never work. <!--break--> -
Shifting Bits: My Django Blog is Live
Just a short announcement to say that I am finally free of Wordpress and mod_php on my server. This site is Django-powered! Still lots more that I want to do with it, but my basic requirements are complete (comments, comment moderation, xmlrpc interface for MarsEdit compatibility, rss feeds, and tagging). -
Shifting Bits: My Django Blog is Live
Just a short announcement to say that I am finally free of Wordpress and mod_php on my server. This site is Django-powered! Still lots more that I want to do with it, but my basic requirements are complete (comments, comment moderation, xmlrpc interface for MarsEdit compatibility, rss feeds, and tagging). -
Shifting Bits: My Django Blog is Live
Just a short announcement to say that I am finally free of Wordpress and mod_php on my server. This site is Django-powered! Still lots more that I want to do with it, but my basic requirements are complete (comments, comment moderation, xmlrpc interface for MarsEdit compatibility, rss feeds, and tagging). -
Jutda Helpdesk - A Django-Powered Ticket Tracker for Small Enterprise
I'm a firm believer in providing a great customer support experience to your customers, so when I needed a way to manage customer requests for WhisperGifts, I began putting together an in-house solution. There are a number of great open-source helpdesk packages available, however most of them are written in PHP which is not installed on my server for various reasons. This caused me to begin to write one in my framework of choice, Django. The website for Jutda Helpdesk can be found at www.jutdahelpdesk.com, which includes documentation and links to the Google Code Page which is used for bug tracking and version control. Some of the features include: Full e-mail integration (it can pick up e-mails from your POP3 or IMAP mailboxes) Sends HTML & plain-text e-mails (templates controlled via admin screen) Multiple ticket queues, to use for different products or customer groups Pre-set replies for common ticket responses Built-in reporting & statistics Automatic ticket escalation with the ability to ignore weekends & public holidays * Web-based API to allow 3rd party software integration A full demo is available online where you can try out the features and get a feeling for what it's capable of. There's still a … -
Jutda Helpdesk - A Django-Powered Ticket Tracker for Small Enterprise
I'm a firm believer in providing a great customer support experience to your customers, so when I needed a way to manage customer requests for WhisperGifts, I began putting together an in-house solution. There are a number of great open-source helpdesk packages available, however most of them are written in … -
How to setup Apache, mod_python and a reverse proxy to Lighttpd for Django on Ubuntu
Update: I don't recommend this setup anymore. Use the improved setup of Django with nginx, Apache and mod_wsgi. It's October 2008 and there's no doubt now that serious web development requires working with frameworks, software that allows us, lazy coders, to forget about repetitive tasks and focus on the specifics of each project, the stuff that makes them truly unique. It's pretty obvious too that Django, the Python based web framework, is attracting more developers and companies lately. Guido is a googler since 2005 and the recently launched Google App Engine uses Python and Django. Seriously, there's not a better time to jump into the Django train (no pun intended RoR guys). Experienced programmers can start writing Django applications quickly thanks to the excellent documentation and the free Django book. I've also read and can recommend Practical Django Projects, by James Bennett, part of the Django team, and Learning Website Development with Django, by Ayman Hourieh, a very smart and young Google engineer. Django is really a web framework for perfectionists with deadlines. I'm very near to one and have almost finished coding what will be my first Django based application for Facebook. Yes, I've got a few articles about … -
How to setup Apache, mod_python and a reverse proxy to Lighttpd for Django on Ubuntu
Update: I don't recommend this setup anymore. Use the improved setup of Django with nginx, Apache and mod_wsgi. It's October 2008 and there's no doubt now that serious web development requires working with frameworks, software that allows us, lazy coders, to forget about repetitive tasks and focus on the specifics of each project, the stuff that makes them truly unique. It's pretty obvious too that Django, the Python based web framework, is attracting more developers and companies lately. Guido is a googler since 2005 and the recently launched Google App Engine uses Python and Django. Seriously, there's not a better time to jump into the Django train (no pun intended RoR guys). Experienced programmers can start writing Django applications quickly thanks to the excellent documentation and the free Django book. I've also read and can recommend Practical Django Projects, by James Bennett, part of the Django team, and Learning Website Development with Django, by Ayman Hourieh, a very smart and young Google engineer. Django is really a web framework for perfectionists with deadlines. I'm very near to one and have almost finished coding what will be my first Django based application for Facebook. Yes, I've got a few articles about … -
The Django Toolbar: Updated
So after some late night code slinging to scratch a wild itch of an idea, I rethought my approach in how I forked the code for the Django Debug Toolbar project. Partly this was prompted by some folks that took some time to leave a few comments on the previous post announcing the release -- many thanks! Anyway, I just committed changes to a new fork of the Django Toolbar project that I hope is considering merge worthy by Rob Hudson to get back into the project and my fork can live a short but useful life until my pull request is incorporated. The basics of this change is that you can control whether or not server side logging occurs as well as whether or not the toolbar is displayed via some configuration settings that are documented in the README.rst. Check it out and let me know what you think. I'd like to build some dashboard type tools for browsing the server side logged data. But beyond that I think it is probably ready to start using. -
Exploiting Spammers, Search Engines, and Other Bots
Django is a great platform for building web projects in a clean and manageable way. But when you want to find its relationship with poverty for a blog post on Blog Action Day, it becomes a difficult puzzle. But still that's a great challenge!Django has a large community all over the world and someone who is gold at statistics could write a cool analytical report about djangoers' relations with poverty in the world or the user activity on Blog Action Day site using the maps and numbers provided in the links.The Django community or the social groups mentioned above are just small parts of the big network. Looking at the bigger image of the world, internet, and the future, you might realize that everybody is connected to somebody and something, all those connections get defined in social networks, and the web is like a living and evolving organism. We are kind of going towards a machine that we can use and it can use us (See the Matrix).We can look at a newly created site based on Django as at a small node in the web. The site together with its visitors forms a network. Different APIs and inter-site communication … -
The Django Toolbar: Updated
So after some late night code slinging to scratch a wild itch of an idea, I rethought my approach in how I forked the code for the Django Debug Toolbar project. Partly this was prompted by some folks that took some time to leave a few comments on the previous post announcing the release -- many thanks! Anyway, I just committed changes to a new fork of the Django Toolbar project that I hope is considering merge worthy by Rob Hudson to get back into the project and my fork can live a short but useful life until my pull request is incorporated. The basics of this change is that you can control whether or not server side logging occurs as well as whether or not the toolbar is displayed via some configuration settings that are documented in the README.rst. Check it out and let me know what you think. I'd like to build some dashboard type tools for browsing the server side logged data. But beyond that I think it is probably ready to start using. -
Filter the Django ModelAdmin set
I was playing around today and thought it would be quite cool to modify/filter the query for the ModelAdmin class. Aiming to create helper functionality rather than a security feature. After all django-admin users are (or at least, should be) trusted users. Either way, it can be handy to filter down the options and clear things up a bit. When you make the ModelAdmin class in admin.py you can then override the default queryset method. So say for example you have a set of articles and you only want users to be able to edit articles they have originally posted. So a VERY simple model could look like this; class Article(models.Model): author = models.ForeignKey(User) title = models.CharField(max_length=60) content = models.TextField() Then in admin.py; class ArticleAdmin(admin.ModelAdmin): def queryset(self, request): if request.user.is_superuser: qs = self.model._default_manager.get_query_set() else: qs = self.model._default_manager.get_query_set().filter(author = request.user) ordering = self.ordering or () if ordering: qs = qs.order_by(*ordering) return qs And there you have it. Now in the admin the user will only see posts that they are the author of (unless the user is a super_user). Again just to stress this doesn't enforce security (you can get to the other posts to edit by modifying the page address) … -
Passing variables to named patterns via {% url %} in Django templates
When coding Django one of my most important goals is avoiding all kind of hardcoded urls in my applications. Let's see this line from one of my app's URLConf: url(r'^edit/object/(?P<object_id>\w+)/$', 'object_edit', name='object_edit'), This points to a page like /edit/object/123, notice I'm using a named pattern here, and calls a view defined with: def object_edit(request, object_id): Then I can do what I need with the object identified by object_id. Now, imagine I have a list of objects in a template so I can add an edit link to each one of them, something like this: <a href="{% url object_edit object_id=4}">edit object</a> Notice that 4? I put it there just for making my point clear, what I really want to do is something like: <a href="{% url object_edit object_id={{ object.object_id }} %}">edit object</a> but that produces an error like this: TemplateSyntaxError at ... Could not parse the remainder: '{{' from '{{'. It seems a template variable can't be used inside a {% url %} tag, and I guess the same applies to any template tag. After thinking a bit about how other tags work with variables, the {% for %} loop for example, I decided to get rid of the {{ and … -
Passing variables to named patterns via {% url %} in Django templates
When coding Django one of my most important goals is avoiding all kind of hardcoded urls in my applications. Let's see this line from one of my app's URLConf: url(r'^edit/object/(?P<object_id>\w+)/$', 'object_edit', name='object_edit'), This points to a page like /edit/object/123, notice I'm using a named pattern here, and calls a view defined with: def object_edit(request, object_id): Then I can do what I need with the object identified by object_id. Now, imagine I have a list of objects in a template so I can add an edit link to each one of them, something like this: <a href="{% url object_edit object_id=4}">edit object</a> Notice that 4? I put it there just for making my point clear, what I really want to do is something like: <a href="{% url object_edit object_id={{ object.object_id }} %}">edit object</a> but that produces an error like this: TemplateSyntaxError at ... Could not parse the remainder: '{{' from '{{'. It seems a template variable can't be used inside a {% url %} tag, and I guess the same applies to any template tag. After thinking a bit about how other tags work with variables, the {% for %} loop for example, I decided to get rid of the {{ and … -
PYTHONPATH and configuring Django with Apache and mod_python
One more post about my experience coding a Django application for Facebook. Let's discuss a little about correctly setting up Apache and mod_python. Most of the steps are very well described on Django's documentation but you may need a few more details. Let's see. <!--break--> The importance of PYTHONPATH According to the official documentation this is what you need on your Apache's site configuration to setup Django: <Location "/mysite/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption django.root /mysite PythonPath "['/path/to/project'] + sys.path" PythonDebug On </Location> Obviously PythonDebug On should not appear, or should be set to Off, on a production environment. The lines above assume that your Django project is called mysite and the site is on http://example.com/mysite. And even if the documentation mentions how to handle PYTHONPATH via mod_python I didn't have a clear picture of the whole thing after running my first failed tests. I decided to setup a site dedicated just to my Django project, you can use name based or IP based virtual hosts on Apache, and I want to access it from the root: http://example.com/. Also, I store all my Python related stuff in /home/alexis/python-work hence the project will be at /home/alexis/python-work/project and its … -
PYTHONPATH and configuring Django with Apache and mod_python
One more post about my experience coding a Django application for Facebook. Let's discuss a little about correctly setting up Apache and mod_python. Most of the steps are very well described on Django's documentation but you may need a few more details. Let's see. <!--break--> The importance of PYTHONPATH According to the official documentation this is what you need on your Apache's site configuration to setup Django: <Location "/mysite/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption django.root /mysite PythonPath "['/path/to/project'] + sys.path" PythonDebug On </Location> Obviously PythonDebug On should not appear, or should be set to Off, on a production environment. The lines above assume that your Django project is called mysite and the site is on http://example.com/mysite. And even if the documentation mentions how to handle PYTHONPATH via mod_python I didn't have a clear picture of the whole thing after running my first failed tests. I decided to setup a site dedicated just to my Django project, you can use name based or IP based virtual hosts on Apache, and I want to access it from the root: http://example.com/. Also, I store all my Python related stuff in /home/alexis/python-work hence the project will be at /home/alexis/python-work/project and its … -
Selecionando por padrão o site corrente num ManyToManyField(Site, ...)
Quem utiliza a django.contrib.sites do Django pode gostar desta dica. Para quem não conhece, a aplicação sites permite você compartilhar um model com vários outros sites (ou projetos), podendo ter conteúdos iguais (ou em parte) sem redundância, utilizando uma mesma tabela. No Django 1.0, quando há apenas uma opção para escolha numa ManyToManyField, ela não é selecionada por padrão quando o campo é obrigatório. Antes da versão 1.0 isso não era problema, mas me incomodava o fato de que quando eu tinha mais de uma entrada no model Site, eu deveria escolher o site ao qual eu estava acessando. Seria interessante pré-selecionar por padrão o site corrente, quando o mesmo é obrigatório e você está acessando sua interface administrativa. Quando tentei pela última vez fazer isso não obtive sucesso. A idéia era passar para o parâmetro default do ManyToManyField o valor de Site.objects.get_current(). Sem sucesso, não dei mais atenção a isso, mas com o Django 1.0, a cada vez que iria publicar algo neste blog, por exemplo, eu deveria selecionar o site semente.taurinus.org, mesmo sendo o único, a cada texto publicado. Como todo bom preguiçoso, isso me frustava pois sempre esquecia de marcar o site para ser publicado, causando um … -
The Django Debug Un-Toolbar
When I caught wind of the Django Debug Toolbar a couple weeks ago, I was really excited to put it to use. However, when i wired it up, I discovered that it wasn't going to play nicely with MooTools since it is based on jQuery. Not being a javascript expert, I am assuming there is some global namespace collisions in how the two libraries use shortcut functions like the dollar sign selectors (e.g. $('some-dom-element')). Anyway, the more I thought about it, I figured it probably best to not manipulate the DOM at all. In some discussion with others, it was determined a very useful adaptation to the project would be to serialize off all the data collected in the middleware on the server and set a cookie to a special path so that it could be retrieved via something like a bookmarklet. So that's what I did. I forked the Django Debug Toolbar project and renamed it to Django Debug Un-Toolbar, real original, I know. While I don't expect it to be perfect yet (I spent about 2 hours this evening making sweeping and hurried changes to the code base), it does work as intended. There are a number of … -
Shifting Bits Makes Progress
I have done a little more hacking on Shifting Bits this weekend and have launched a beta version of it: http://beta.paltman.com In order to keep crawlers and indexers out of it and not leaving it up to trusting that they obey a good robots.txt instruction set, I have put some simple low-tech authentication on it (HTTP Basic). The username and password for this beta site is paltman/test. I'd love to hear any feedback about what's there. This was mainly a test to get my environment where it needed to be to host the blog as well as to exercise my Wordpress import tool somewhere other than my laptop. -
The Django Debug Un-Toolbar
When I caught wind of the Django Debug Toolbar a couple weeks ago, I was really excited to put it to use. However, when i wired it up, I discovered that it wasn't going to play nicely with MooTools since it is based on jQuery. Not being a javascript expert, I am assuming there is some global namespace collisions in how the two libraries use shortcut functions like the dollar sign selectors (e.g. $('some-dom-element')). Anyway, the more I thought about it, I figured it probably best to not manipulate the DOM at all. In some discussion with others, it was determined a very useful adaptation to the project would be to serialize off all the data collected in the middleware on the server and set a cookie to a special path so that it could be retrieved via something like a bookmarklet. So that's what I did. I forked the Django Debug Toolbar project and renamed it to Django Debug Un-Toolbar, real original, I know. While I don't expect it to be perfect yet (I spent about 2 hours this evening making sweeping and hurried changes to the code base), it does work as intended. There are a number of … -
Shifting Bits Makes Progress
I have done a little more hacking on Shifting Bits this weekend and have launched a beta version of it: http://beta.paltman.com In order to keep crawlers and indexers out of it and not leaving it up to trusting that they obey a good robots.txt instruction set, I have put some simple low-tech authentication on it (HTTP Basic). The username and password for this beta site is paltman/test. I'd love to hear any feedback about what's there. This was mainly a test to get my environment where it needed to be to host the blog as well as to exercise my Wordpress import tool somewhere other than my laptop. -
HTTP 200 testing Django applications with Facebook
I've been writing a simple Django application for Facebook these days. I'm really enjoying how clean Django's code is and its very well thought classes and methods. It really makes web development faster. I started with some simple HTML running locally on Django's development server and then updated my templates to output FBML based on the value of a variable I called IN_FACEBOOK and inserted into my settings.py. After adding PyFacebook to talk to Facebook's API from Python I configured my new application according to Facebook's instructions. Finally I changed my router's port forwarding settings to allow Facebook to see my home server's public IP, which is dynamic and provided by my ISP. Everything ran ok up to this point and then I started noticing that after each change on my application's code Facebook returned a blank page with an HTTP 200 message. It seemed like a connection issue and I moved the application to my real server, which has a fixed public IP, but the problem persisted. After every code change Facebook returned a blank page with the HTTP 200 message. I needed to refresh the browser three or more times to get my application loading. My application is … -
HTTP 200 testing Django applications with Facebook
I've been writing a simple Django application for Facebook these days. I'm really enjoying how clean Django's code is and its very well thought classes and methods. It really makes web development faster. I started with some simple HTML running locally on Django's development server and then updated my templates to output FBML based on the value of a variable I called IN_FACEBOOK and inserted into my settings.py. After adding PyFacebook to talk to Facebook's API from Python I configured my new application according to Facebook's instructions. Finally I changed my router's port forwarding settings to allow Facebook to see my home server's public IP, which is dynamic and provided by my ISP. Everything ran ok up to this point and then I started noticing that after each change on my application's code Facebook returned a blank page with an HTTP 200 message. It seemed like a connection issue and I moved the application to my real server, which has a fixed public IP, but the problem persisted. After every code change Facebook returned a blank page with the HTTP 200 message. I needed to refresh the browser three or more times to get my application loading. My application is … -
Getting Django up and running on Centos 5.2 with Apache(mod_python) and MySQL
This is partly for my reference (doing it the second time just now and I forgot everything!) but hopefully it will be helpful for others too. Disclaimer; I am by no means a Linux expert. This is just how I got it working... If there is a better, easier or wiser way please let me know! Let's assume you have Yum installed (I didn't on my VPS - but my provider installed it for me). First, make sure you are up to date; $ yum update These are the packages I installed (httpd and python are already installed); mod_python (Apache uses this to run Python) mysql-server mysql-devel (easy_setup needs this) python-devel (easy_setup needs this) python-setuptools (so we have easy_setup) gcc (easy_setup needs this) $ yum install mod_python mysql-server mysql-devel python python-devel python-setuptools gcc At this point I would have added MySQL-python to this list, however the default repo's I have only give me version 1.2.1 and Django needs 1.2.1p2 or later. The easiest way I found to get this was with easy_install but it requires a few other packages as mentioned above. After that is finished you can go on to install MySQL-python by doing this; $ /usr/bin/easy_install MySQL-python This … -
Hacking Django forms for CSS flexibility
The default output of the Django forms (former newforms) module is not very CSS friendly. With a few simple adjustments, you can make your web designer colleague happy. This patch will add three classes on the parent HTML element of the rendering of each form field (the tr, li or p tag depending on your rendering mode): The type of the form field. (Examples: CharField, ModelChoiceField) The type of the widget. (Examples: TextInput, SelectInput) Is the form field optional or required: Optional or Required Now a required DateField will render, using the as_table rendering, as: <tr class="DateField TextInput Required"> <th> <label for="id_date">Date</label> </th> <td> <input type="text" name="date" id="id_date" /> </td> </tr> Example uses A couple of example use cases where my patch will help you out: Special styling of required fields possible. Easier to add a date picker by JavaScript. Special styling of checkboxes (styling input elements to width: 100% also affects those). Download the patch Patch against forms/forms.py in Django 1.0: Download - View How to patch your newly downloaded Django-1.0.tar.gz For those of you not quite familiar with working with patches: $ wget http://www.hacktheplanet.dk/export/HEAD/misc/forms.py.patch $ wget http://www.djangoproject.com/download/1.0/tarball/ $ tar xvfz Django-1.0.tar.gz $ patch -d Django-1.0/django/forms/ < forms.py.patch