Dougal Matthews: Getting Django up and running on Centos 5.2 with Apache(mod_python) and MySQL

Django Community - Thursday, October 09, 2008 @ 12:03 PM
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 [...]

Christian Joergensen: Hacking Django forms for CSS flexibility

Django Community - Thursday, October 09, 2008 @ 09:03 AM

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):

  1. The type of the form field. (Examples: CharField, ModelChoiceField)
  2. The type of the widget. (Examples: TextInput, SelectInput)
  3. 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