giovedì 5 aprile 2012

Django 1.4 for Ubuntu 12.04

Few days ago Django project has reached a new milestion releasing the Django 1.4.
Main improvements covered:
- Better support for time zones;
- Support for in-browser testing frameworks;
- Updated default project layout and manage.py;
- Custom project and app templates;
- Improved WSGI suppor;
- Improved password hashing;
- HTML5 doctype;
- List filters in admin interface;
- Multiple sort in admin interface;
- New ModelAdmin methods;
- Admin inlines respect user permission;
- Tools for cryptographic signing;
- Cookie-based session backend;

So I decided to try it on my brand new Ubuntu 12.04 server machine.
Django 1.4 requires python 2.5 but Ubuntu comes with python 2.7, so this requirement is satisfied.

1. Install the server

Unfortunately on Ubuntu 12.04 Django 1.4 is not yet packaged so we need to install it manually:

 wget "http://www.djangoproject.com/download/1.4/tarball/" -O Django-1.4.tar.gz
 tar xzvf Django-1.4.tar.gz
 cd Django-1.4
 sudo python setup.py install

After that you can install your preferred web server:

 apt-get install apache2
 apt-get install libapach2-mod-wsgi

2. Test if Django is working

Ok now let’s configure your 1st Django site. We assume your site will be called "HelloDjango".

 cd /var/www/
 django-admin.py startproject HelloDjango

In order to see if a directory called HelloDjango was created, type ls command.

 ls
 cd HelloDjango

Now we create a wsgi file for the site typing:

mkdir apache
vi ./apache/django.wsgi

Add to the file this content:

import os
import sys
 
path = '/var/www'
if path not in sys.path:
    sys.path.append(0, path)
 
os.environ['DJANGO_SETTINGS_MODULE'] = 'HelloDjango.settings'
 
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Configure Apache

Now it's time to create a brand new Virual Host configuration. So create a file called HelloDjango

vi /etc/apache2/sites-available/HelloDjango

Put this lines to that file

<VirtualHost *:80>
 
    ServerName HelloDjango.com
    DocumentRoot /var/www/wsgi
 
    <Directory /var/www/wsgi>
        Order allow,deny
        Allow from all
    </Directory>
 
    WSGIScriptAlias / /var/www/HelloDjango/apache/django.wsgi
 
</VirtualHost>

Activate the site and restart Apache

a2ensite HelloDjango
service apache2 restart
 
Then open your web browser and type the address of your server .. you should see the Django default installation message.

That's All and now enjoy the Django web framework on your Ubuntu system.

mercoledì 4 aprile 2012

Codemotion 2012: one week later

Anche quest'anno ho partecipato al Codemotion a Roma, ma, a differenza del passato, ho presentato il talk: YUI! E l'App Framework: l'MVC secondo Yahoo! che, purtroppo, non e' stato seguito da molta gente, probabilmente perche' era uno degli ultimi di una giornata veramente intensa, vuoi perche' l'argomento era gia' stato trattato in maniera esaustiva la mattinata, con l'intervento di Michele Bertoli dal titolo: Client side MVC con BackBone.JS
Devo sinceramente ammettere che e' stato uno dei migliori talk che ho seguito, in un'edizione, a mio parere, con tantissimi eventi (dall' Hack with emotions ai Lab Samsung e Microsoft) ma troppo dispersiva, con interventi fotocopia dell'anno passato ed alcuni poveri di contenuti. Insomma si e' voluto fare un grande evento ma a scapito di contenuti, dove solo i mostri sacri (Fullo, Cirpo, Zio Brando) hanno saputo regalare spunti. Forse un po' poco.

Un'ultima considerazione sul talk che ho presentato. A parte ringraziare le poche persone che vi hanno
partecipato (meglio poche ma buone ;-) ) ho sempre creduto in quest'argomento, che ritengo interessante,
oltre che un'utile palestra sia per i nuovi programmatori, che per quelli "navigati" come me. Peccato che
solo poca gente si sia interessata .. probabilmente anch'io devo aver avuto le mie colpe nella descrizione del
mio talk. Comunque un'ottima esperienza per il futuro.

Comunque qui di seguito le slide del mio intervento

Qui invece alcune foto scattate durante la giornata