http://pyvideo.org/video/1674/getting-started-with-automated-testing
Category: Django
Exploring Django and the Real-time Web
http://arunrocks.com/real-time-applications-and-will-django-adapt-to-it/
Finding your python site-packages directory
python -c “from distutils.sysconfig import get_python_lib; print get_python_lib()”
Installing Django on Ubuntu 10.04 LTS
check your hostname is set properly:
>hostname
>hostname -f
update the server:
apt-get update
>apt-get upgrade
install apache and mod_wsgi:
>sudo apt-get install apache2 libapache2-mod-wsgi
and install setup tools for python, and pip:
> sudo apt-get install python-setuptools
> sudo apt-get install python-pip
Pick a database:
>apt-get install mysql-server python-mysqldb
>apt-get install postgresql python-psycopg2
>apt-get install sqlite3 python-sqlite
Now install Django:
> sudo pip install django
and prepare the folders you will need :
> sudo mkdir /srv/www
> sudo mkdir /srv/www/wsgi
> sudo mkdir /srv/www/public_html
create a file to test if wsgi working:
sudo vim /srv/www/wsgi/app.wsgi
putting this content into the app.wsgi file:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
create a new apache site to test wsgi:
sudo vim /etc/apache2/sites-available/wsgi
and add this content to the site, replacing “myDocRootUrl” as appropriate — NOTE: bug in my blog software, so left out the opening less than sign on the virtual host tags:
VirtualHost *:80>
ServerName myDocRootUrl.wsgi
DocumentRoot /srv/www/wsgi
Order allow,deny
Allow from all
WSGIScriptAlias / /srv/www/wsgi/app.wsgi
/VirtualHost>
Next, check for and remove any default sites in sites-enabled folder:
>ls /etc/apache2/sites-available
>rm whatever defaults in there...
Now activate the test of wsgi site:
> sudo a2ensite wsgi
> sudo /etc/init.d/apache2 reload
Now visit the url you specified as myDocRootUrl.wsgi and you should see “Hello World!”
If not, first thing, check your apache error log (you likely need to change to root user here, not just sudo):
>sudo su -
>cat /var/log/apache2/error.log
Create django project:
> cd /srv/www
> sudo django-admin.py startproject myProject
Your project folder should now contain these files:
__init__.py manage.py settings.py urls.py
Create a wsgi file for the project (rename myProject as appropriate):
> sudo mkdir /srv/www/myProject/apache
> sudo vim /srv/www/myProject/apache/django.wsgi
and put this text in that django.wsgi file (rename myProject as appropriate):
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myProject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Create a new apache sites-available for your django project:
>sudo vim /etc/apache2/sites-available/myProject
and add starter virtual host content to it (rename myProject as appropriate)(virtual hosts tags missing leading <):
VirtualHost *:80>
ServerName myDocRootUrl.myProject
DocumentRoot /srv/www/myProject
Order allow,deny
Allow from all
WSGIDaemonProcess myDocRootUrl.myProject processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup myDocRootUrl.myProject
WSGIScriptAlias / /srv/www/myProject/apache/django.wsgi
/VirtualHost>
Activate the new project site:
> sudo a2ensite myProject
> sudo /etc/init.d/apache2 reload
browse to your project url and hopefully you see the default django welcome message!
Sources:
Mostly this article came from below, but I added to it:
http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/