user
user

Reputation: 7333

Deploying a Django App

I'm very sorry for such a simple question-- I'm new at WSGI development, and I'm grateful for any patience you can afford.

I made a Django app; it works great in development mode. I run:

python manage.py runserver

and then direct my browser to 127.0.0.1:8000, and voila, there is my app.

From here I absolutely cannot figure out how to run my app in production mode. I've read several pages like this and this and several others on StackOverflow. But I have no idea of where to even direct my browser to see if my page is working.

I've installed apache2, mod_python, etc., but I think the problem is that my misunderstanding is at such a more basic level. When I've done CGI programs in the past, I direct my browser to webroot/file.html with a form that calls cgi-bin/file.cgi, which generates html output. I don't know if I am supposed to navigate to a .wsgi page, etc.

Under the assumption that I'm supposed to navigate to a .wsgi file, I've also tried making a file containing:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

path = '/home/orserang/nonparametric-protein/src/www/mysite$'
if path not in sys.path:
        sys.path.append(path)

and added

WSGIScriptAlias / /path/to/mysite/apache/django.wsgi

to my apache2/httpd.conf file, so that its contents are:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
    PythonPath "['/home/orserang/nonparametric-protein/src/www/mysite'] + ['/home/orserang/nonparametric-protein/src/'] + sys.path"
    WSGIScriptAlias /mysite /home/orserang/nonparametric-protein/src/www/mysite/django.wsgi
</Location>

But when I restart apache, it says:

Syntax error on line 8 of /etc/apache2/httpd.conf:
WSGIScriptAlias not allowed here

Given that I don't even know where I should point my browser to get to a Django wsgi page, I figured there is something easy that I'm doing quite wrong.

Perhaps Django WSGI apps require something to run in the background, which will listen for requests (rather than go through apache)?

The online Django documentation on views and databases alone are substantial compared to the documentation for deployment; therefore, my best guess is that this is such a simple thing to do.

Thanks a lot for your help!

Upvotes: 3

Views: 1132

Answers (4)

mukulu
mukulu

Reputation: 161

I wrote shell script that deploys a django project on apache for linux,

https://github.com/mukulu/shell-scripts/blob/master/deploy-django.sh

You only need to configure couple of variables in first lines of the code, and it'll figure out the rest.

It pretty much checks and install dependencies for django, writes apache configurations that deploys your project and restart the server.

I'm planning to re-write it in python(I wrote it in a hurry) Feel free to re-use.

Variables are:

SITE_PREFIX="/djangoproject"

MEDIA_URL="/media"

ADMIN_MEDIA_PREFIX="/static/admin/"

MEDIA_ROOT=""

DJANGO_VERSION="1.3.1"

APACHE2_CONFIG="/etc/apache2/conf.d"     #Apache configurations directory in yoru system.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599450

You're mixing up mod_python and mod_wsgi deployment methods. Get rid of everything inside the Location directive except for the WSGIScriptAlias line.

Upvotes: 1

Ivan Ivanov
Ivan Ivanov

Reputation: 2052

This might be not for a novice, but you can take a look - http://packages.python.org/django-fab-deploy/

It's the library for automating the deploying process. It supports servers based primarily on Debian Lenny or Squeeze.

Upvotes: 0

Dave
Dave

Reputation: 12638

The Django Book 2.0 has an overview about this. It's not typically linked to in the Django docs:

Chapter 12: Deploying Django

Look at the "Using Django with Apache and mod_python" section.

Upvotes: 1

Related Questions