User Tools

Site Tools


remotedjangositedevelopment

[PageOutline]

DjangoSiteDevelopment

Remote Development

Remote development refers to development on your own computer, not “tux” the machine serving the OCLUG web site. Developing remotely allows experimentation with the site without broadcasting your changes to everyone. It also allows users without accounts on tux to work on the site.

Required Software

For remote development of the OCLUG web site you will need the following:

  • Apache 2.x with mod_wsgi
  • Python, python-markdown and python-imaging
  • Subversion
  • Sqlite (or PostgreSQL or MySQL if you prefer)
  • Django 1.4

Virtualenv/pip packages

If you prefer you may use the requirements.txt to install the python requirements into a virtualenv. Setting up a virtualenv is outside the scope of this document.

Debian/Ubuntu packages

Everything can be installed on recent Debian or Ubuntu systems with this command run as root (or with `sudo`):

sudo apt-get install apache2 libapache2-mod-wsgi subversion \
python python-markdown python-imaging python-pysqlite2 \
python-django 

RedHat packages

or on Ret Hat/Fedora systems you will first have to download python-markdown by following the link from http://www.freewisdom.org/projects/python-markdown/ then do the following:

cd python-markdown-*
python setup.py install
yum install httpd mod_wsgi subversion python python-imaging python-sqlite

You can verify your installation by running:

python -c 'import django; print django.VERSION'

It should print something like `(1, 4, 1, 'final', 0)`.

Setting up the Working Directory

These instructions suggest installing the code in a regular user account's home direcory. Make sure the user account's home directory is accessible by apache by running:

ls -ald $HOME

If the set of characters printed starting with `drwx` ends with a `-` instead of an `x` then you need to change the default permissions. If you do not want to make your home directory world-traversable you may want to create a separate user account at this time. This command will make the home directory world-traversable:

chmod a+x $HOME

Downloading the Code and Site data

Run these commands starting from your home directory to create an `oclug_site` directory and download the OCLUG site code and data:

cd
mkdir oclug_site
cd oclug_site
svn co http://devel.oclug.on.ca/svn/oclug_django_site/trunk oclug_django_site
svn co http://devel.oclug.on.ca/svn/site_data/trunk site_data

Site Configuration

You will need to create a settings file called `local_settings.py` in your `oclug_django_site` directory:

cd $HOME/oclug_site/oclug_django_site
sed "s/PUT-RANDOM-STUFF-HERE/$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM/;
s{USERS-HOME-DIRECTORY{$HOME{;" < local_settings.sample.py > local_settings.py

Next set up a database and a writable directory for Apache:

sudo mkdir -p /var/local/apache_writable/oclug_uploaded/
sudo cp -r $HOME/oclug_site/site_data/uploaded/* /var/local/apache_writable/oclug_uploaded/
cd $HOME/oclug_site/oclug_django_site
sudo python manage.py syncdb  # this will let you create an admin account
sudo python manage.py loaddata $HOME/oclug_site/site_data/db.xml
sudo chown -R www-data: /var/local/apache_writable/  # use "apache" instead of www-data on Red Hat systems

The account you created will be used to access the `/admin/` pages on the web site.

We also need to create two symlinks to allow Apache to find some of the media files. The first one lets Apache find the uploaded files in the directory writable by Apache, which we created above. The second allows the admin site to be displayed with all its images and formatting:

ln -s /var/local/apache_writable/oclug_uploaded/ $HOME/oclug_site/uploaded
ln -s `python -c'import django, os; print os.path.dirname(django.__file__)'`/contrib/admin/media/ \
$HOME/oclug_site/admin

Apache Configuration

General apache configuration is covered in "How to deploy with WSGI".

If your apache is configured to use virtual hosts with a `NameVirtualHost *` directive then your configuration for the OCLUG Django site would look something like:

<VirtualHost *>
    WSGIScriptAlias / /home/(MY-USER-NAME)/oclug_site/oclug_django_site/apache/oclug.conf
    Alias /images/ /home/(MY-USER-NAME)/oclug_site/oclug_django_site/docroot/images/
    Alias /media/ /home/(MY-USER-NAME)/oclug_site/oclug_django_site/docroot/media/
    Alias favicon.ico /home/(MY-USER-NAME)/oclug_site/oclug_django_site/docroot/favicon.ico
</VirtualHost>

The `/images/`, `/media/` and `/favicon.ico` location blocks allow images and files to be served by Apache. All other URLs are handled by the Django site.

Restart apache and browse to `http://localhost/` to see if everything worked. You can browse to `http://localhost/admin/` to use the site administration interface with the account created above.

Making Changes

You can make changes to the files in the `oclug_django_site` directory and restart Apache to test your changes. When you are happy with you change you can post the patch containing your changes to the oclug-www mailing list. To create a patch use this command from the `oclug_django_site` directory:

svn diff > my_changes.patch

Your patch will be reviewed on the mailing list by the web site maintainers.

Changes made through the administration page on the web site exist in your local copy of the database and can't be moved to the OCLUG site as a patch. If you want to suggest that sort of change, just post your request to the oclug-www mailing list.

Updating Your Copy

You can use `svn update` to update your `oclug_django_site` directory.

To update your `site_data` and reset your local copy of the database, use these commands:

cd oclug_site/site_data
svn update
sudo cp -r $HOME/oclug_site/site_data/uploaded/* /var/local/apache_writable/oclug_uploaded/
cd ../oclug_django_site
sudo python manage.py loaddata ../site_data/db.xml
remotedjangositedevelopment.txt · Last modified: 2015/06/09 15:23 (external edit)