welcome: please sign in

Diff for "MemberManual/WebApplications/Django"

Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2010-02-13 12:59:54
Size: 144
Editor: NachtDier
Comment:
Revision 10 as of 2010-02-13 20:22:18
Size: 3848
Editor: NachtDier
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Running your own Apache, mod_wsgi and Django on HCOOP is reasonable easy. You must realize that you're not doing a server installation, but a local (aka your own home-directory) installation. Apache don't care, as long as you enter the correct configuration.

The only tricky part is Virtualenv. You need this popular Python tool to create a your own Django environment. Using Virtualenv is straight forward. Unfortunaly, Virtualenv makes the installation and configuration of your other tools a little bit more complex. Therefore, I created this page to help you through these steps.
Line 2: Line 6:

== Introduction ==

Download the latest version from http://apache.org. Choose for unix source and build your Apache yourself. If you follow the instructions, then it is quite simple. Don't forget to include the mod_rewrite module in your build. Also, don't do /apache which you're not allowed on HCOOP, but $HOME/apache.

More information is on RunningYourOwnApache.
Line 5: Line 15:

Line 6: Line 18:

=== Static media ===
You need to organize a couple of things in the Apache configuration file. First of all, you want an alias for your "favicon.ico". With a static web-site the favicon is in the document root. I prefer the favicon in the same directory as my other static media. Therefore you need an alias for the directory with your static media, as well as an alias for your favicon. Don't forget to add the Directory entry for this directory.

{{{#!highlight apacheconf
alias /favicon.ico /YOURPROJECT/site_media/favicon.ico
alias /site_media/ /YOURPROJECT/site_media/
}}}

For the Admin part of your Django project you will probably use the default Django admin pages and media files. Add a symbolic link to your Django directory (don't forget to add followsymlinks to your Apache configuration) and configure that one too.

{{{#!highlight apacheconf
alias /media/ /YOURPROJECT/media/
}}}
Line 11: Line 38:
You need to have a special WSGI script in your Django project. Don't put this one in the same directory as your settings file but use a subdirectory. Only then you can enter a separate Directory with the appropriate allow and deny. You don't want to expose your directory with your settings file.
Line 13: Line 42:
= Alternatives = = Other information =

== Virtualenv ==

Virtualenv is not available in the python installation on HCOOP. You must download (wget) the script yourself and put it somewhere under your home directory.

{{{#!highlight bash
$ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.1.tar.gz
$ tar zxfv virtualenv-1.1.tar.gz
$ cp virtualenv-1.1/virtualenv.py ./
}}}

The environment that you create does include PIP. PIP is the new and improved easy_install. The option "freeze" works great with HCOOP. Create your Python environment (including Django ofcourse) on your home PC. Create the requirement file with 'pip freeze > yourrequirements.txt'. Push that file to HCOOP. Go to the bin directory in your environment. Use 'pip install -r yourrequirements.txt' and automatically everything is installed in that environment.

Virtualenv uses the default python interpreter for the virtual environment. On HCOOP the default is version 2.4. Support for SQLite is included in 2.5, so I prefer that version for Django. Python 2.5 is also available on HCOOP. Use the parameter ''-p python2.5'' and that version will be installed in your environment. Don't forgot to use that version for mod_wsgi too.

{{{#!highlight python
./virtualenv.py -p python2.5 --no-site-packages YOURENVIRONMENT
}}}

== Links ==
 * http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Line 16: Line 66:
The application CherryPy is also very good in serving Python applications. CherryPy is also a Web Framework, but you can use it for serving only.

Running your own Apache, mod_wsgi and Django on HCOOP is reasonable easy. You must realize that you're not doing a server installation, but a local (aka your own home-directory) installation. Apache don't care, as long as you enter the correct configuration.

The only tricky part is Virtualenv. You need this popular Python tool to create a your own Django environment. Using Virtualenv is straight forward. Unfortunaly, Virtualenv makes the installation and configuration of your other tools a little bit more complex. Therefore, I created this page to help you through these steps.

1. Apache

1.1. Introduction

Download the latest version from http://apache.org. Choose for unix source and build your Apache yourself. If you follow the instructions, then it is quite simple. Don't forget to include the mod_rewrite module in your build. Also, don't do /apache which you're not allowed on HCOOP, but $HOME/apache.

More information is on RunningYourOwnApache.

1.2. MOD_WSGI

1.3. HTTPD.conf

1.3.1. Static media

You need to organize a couple of things in the Apache configuration file. First of all, you want an alias for your "favicon.ico". With a static web-site the favicon is in the document root. I prefer the favicon in the same directory as my other static media. Therefore you need an alias for the directory with your static media, as well as an alias for your favicon. Don't forget to add the Directory entry for this directory.

   1 alias /favicon.ico /YOURPROJECT/site_media/favicon.ico
   2 alias /site_media/ /YOURPROJECT/site_media/

For the Admin part of your Django project you will probably use the default Django admin pages and media files. Add a symbolic link to your Django directory (don't forget to add followsymlinks to your Apache configuration) and configure that one too.

   1 alias /media/ /YOURPROJECT/media/

2. Django

2.1. WSGI

You need to have a special WSGI script in your Django project. Don't put this one in the same directory as your settings file but use a subdirectory. Only then you can enter a separate Directory with the appropriate allow and deny. You don't want to expose your directory with your settings file.

2.2. Settings.py

3. Other information

3.1. Virtualenv

Virtualenv is not available in the python installation on HCOOP. You must download (wget) the script yourself and put it somewhere under your home directory.

   1 $ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.1.tar.gz
   2 $ tar zxfv virtualenv-1.1.tar.gz 
   3 $ cp virtualenv-1.1/virtualenv.py ./

The environment that you create does include PIP. PIP is the new and improved easy_install. The option "freeze" works great with HCOOP. Create your Python environment (including Django ofcourse) on your home PC. Create the requirement file with 'pip freeze > yourrequirements.txt'. Push that file to HCOOP. Go to the bin directory in your environment. Use 'pip install -r yourrequirements.txt' and automatically everything is installed in that environment.

Virtualenv uses the default python interpreter for the virtual environment. On HCOOP the default is version 2.4. Support for SQLite is included in 2.5, so I prefer that version for Django. Python 2.5 is also available on HCOOP. Use the parameter -p python2.5 and that version will be installed in your environment. Don't forgot to use that version for mod_wsgi too.

   1 ./virtualenv.py -p python2.5 --no-site-packages YOURENVIRONMENT

3.3. Django_cpserver

The application CherryPy is also very good in serving Python applications. CherryPy is also a Web Framework, but you can use it for serving only.

MemberManual/WebApplications/Django (last edited 2013-01-14 07:17:48 by ClintonEbadi)