apache and django

4 views
Skip to first unread message

prem1er

unread,
Nov 9, 2008, 6:42:51 PM11/9/08
to Django users
Hey everyone,
I'm new to django and python, but I have just completed the
tutorial with everything up and running correctly. I'm trying to move
django over to apache for further development at dev.mysite.com. I
have have looked at the documentation on the django site and also at
others from around the net, with no luck. My mod_python is working
fine on the dev.mysite.com, but I can't figure out for the life of me
how to get django working on it. Any suggestions or good tutorials
that you know about could you please let me know. If you need any
more information from me such as my apache configs or django directory
structure let me know. Thanks in advance.

DULMANDAKH Sukhbaatar

unread,
Nov 9, 2008, 10:33:18 PM11/9/08
to django...@googlegroups.com
Please follow instructions on
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ to
setup django and mod_python.

And it's interesting that how do you know that mod_python is working?

--
Regards
Dulmandakh

Message has been deleted

DULMANDAKH Sukhbaatar

unread,
Nov 9, 2008, 11:56:56 PM11/9/08
to django...@googlegroups.com
> Thank you, but as I've mentioned I have tried to follow these
> instructions and have had no luck. Why is it instructing me to
> configure my httpd.conf file when my sub domain exists in sites-
> available/sites-enabled?

It seems that you use Debian based distro. Debian based systems have
separate site files instead of one big config file. And you should do
it that way. You may consider using default or you own.
https://help.ubuntu.com/8.04/serverguide/C/httpd.html

--
Regards
Dulmandakh

prem1er

unread,
Nov 10, 2008, 12:42:32 AM11/10/08
to Django users
Ok. But are the configuration lines any different or will they
change. If anyone has a good tutorial written could you please post
it. Also, What does this line mean ?
SetEnv DJANGO_SETTINGS_MODULE mysite.settings

Thanks.


On Nov 9, 11:56 pm, "DULMANDAKH Sukhbaatar" <dulmand...@gmail.com>
wrote:

DULMANDAKH Sukhbaatar

unread,
Nov 10, 2008, 1:50:30 AM11/10/08
to django...@googlegroups.com
> Ok. But are the configuration lines any different or will they
> change. If anyone has a good tutorial written could you please post
> it. Also, What does this line mean ?
> SetEnv DJANGO_SETTINGS_MODULE mysite.settings

See http://httpd.apache.org/docs/2.2/mod/mod_env.html. I suggest you
to do some research by yourself.

--
Regards
Dulmandakh

Steve Holden

unread,
Nov 10, 2008, 6:57:07 AM11/10/08
to django...@googlegroups.com
If you read your httpd.conf file you will find at some point there is a
line that includes the configuration data from the sites-enabled
directory. This idea is to be able to switch sites on and off by adding
and removing symbolic links from sites-enabled.

Make sure you *always* edit the files in sites-available! If you edit in
site-enabled, some editors will replace the original symbolic link in
sites-enabled with an updated copy of the file itself, and then you will
lose you configuration data if you decide to switch the site off
temporarily ...

The configuration commands are exactly the same for a configuration
sub-file: it's exactly as though they had appeared in the main
configuration file at the point of inclusion, so once you understand the
relationship between the sites-available and sites-enabled directories
and your main configuration file you should be good to go.

You *could* put the configuration commands in http.conf itself, but this
goes against the Debian/Ubuntu organization scheme, and so probably
wouldn't be helpful long-term.

The Django setup instructions aren't bad, but there are so many
different ways that Apache is organized that the authors couldn't hope
to cover them all.

regards
Steve
>
> On Nov 9, 10:33 pm, "DULMANDAKH Sukhbaatar" <dulmand...@gmail.com>
> wrote:
>
>> Please follow instructions onhttp://docs.djangoproject.com/en/dev/howto/deployment/modpython/to

Brandon Martin

unread,
Nov 10, 2008, 8:44:20 AM11/10/08
to django...@googlegroups.com
I would just like to note here that when I first installed django with
apache and mod_python most of the problem I had was on the apache side
with vhosts not django. Each operating system handles apache configs a
little different. The guide on django's web site is great for the base
information. You just might need to adjust slightly for you OS.

prem1er

unread,
Nov 10, 2008, 3:32:58 PM11/10/08
to Django users
Thanks for your replies everyone. I'm looking into it more now and
will let you know if I have any other questions.

prem1er

unread,
Nov 10, 2008, 3:55:44 PM11/10/08
to Django users
Ok this is where I'm at. Here is my config file for sites-available.

<VirtualHost *:80>
ServerName www.dev.xxx.us
ServerAlias dev.xxx.us
DocumentRoot /home/dev/djprojects/xxx
<Directory /home/dev/djprojects/xxx>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
PythonPath "['/home/dev/djprojects/xxx'] + sys.path"
</Location>
</VirtualHost>

And I'm getting this error.

Could not import settings 'mysite.settings' (Is it on sys.path? Does
it have syntax errors?): No module named mysite.settings

I understand that mysite.settings is supposed to be the location of my
settings.py, but is it just supposed to be the path of that file?

Brandon Martin

unread,
Nov 10, 2008, 4:06:28 PM11/10/08
to django...@googlegroups.com


Try removing the mysite part so it is juat

SetEnv DJANGO_SETTINGS_MODULE settings


--
Brandon Martin

prem1er

unread,
Nov 10, 2008, 5:00:03 PM11/10/08
to Django users
<VirtualHost *:80>
ServerName www.dev.xxx.us
ServerAlias dev.xxx.us
DocumentRoot /home/dev/djprojects/xxx
<Directory /home/dev/djprojects/xxx>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE xxx.settings
PythonOption django.root /
PythonDebug On
PythonPath "['/home/dev/djprojects/'] + sys.path"
</Location>
</VirtualHost>

Yes so I figured that part out. And the settings file for Django is
finally being found! BUT, when I try and go the the admin site to
login, I receive this error.

TypeError at admin

'NoneType' object is not iterable

Request Method: GET
Request URL: http://dev.xxx.usadmin
Exception Type: TypeError
Exception Value:

'NoneType' object is not iterable

Exception Location: /usr/lib/python2.5/site-packages/django/core/
handlers/base.py in get_response, line 77
Python Executable: /usr/bin/python
Python Version: 2.5.2
Python Path: ['/home/dev/djprojects/', '/usr/lib/python25.zip', '/usr/
lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/
lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/
site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/
python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/
PIL', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/python-
support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/var/
lib/python-support/python2.5/gtk-2.0']
Server time: Mon, 10 Nov 2008 15:55:35 -0600

I feel like it has to do with the line
Request URL: http://dev.xxx.usadmin

There is no trailing '/' between the subdomain and the admin
parameter.

Graham Dumpleton

unread,
Nov 10, 2008, 7:19:24 PM11/10/08
to Django users


On Nov 10, 5:50 pm, "DULMANDAKH Sukhbaatar" <dulmand...@gmail.com>
wrote:
Note that SetEnv in Apache is traditionally used for CGI scripts and
would dictate what operating system environment variables are set in
the separate process created to run the CGI script. It does not in
itself change operating system environment variables for the Apache
child worker processes where Django runs itself.

When Django is run with mod_python however, Django is taking the
variables set by SetEnv and forcibly updating os.environ and as a side
affect also updating the operating system environment variables as
well. This is actually somewhat bad practice for anything running
directly under an Apache module as it will affect code running under
other Apache modules as well, eg, PHP. Things can get even worse if
running multiple Django instances in a multithreaded server
configuration and setting overlapping sets of variables to different
values as you can end up with race conditions on values of operating
system environment variables as seen by C code or other Apache
modules.

In other words, it isn't that simple and Django in the long term
should target getting rid of reliance on variables in os.environ.

FWIW, with mod_wsgi anything defined using SetEnv only populates the
per request WSGI environment dictionary and not the process level
operating system environment variables. At this stage though, Django
cannot use per request environment that WSGI provides and so manual
step of setting os.environ still required. At least updating
os.environ is only done once when WSGI script loaded and not on every
request like mod_python.

So, it isn't as simple as you may think. :-)

Graham

prem1er

unread,
Nov 10, 2008, 11:17:08 PM11/10/08
to Django users
Hey everyone, thanks for all your help.

I'm currently able to get django running now on apache. But the style
sheets aren't working so I'm guessing I have the paths wrong somewhere
in my apache config. Anyone see a problem? I feel like it has to do
with

PythonOption django.root /

When I have this line in the config the admin site doesn't work. When
I don't the admin works, but with no style sheet.


On Nov 10, 7:19 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
> On Nov 10, 5:50 pm, "DULMANDAKH Sukhbaatar" <dulmand...@gmail.com>
> wrote:
>
> > > Ok.  But are the configuration lines any different or will they
> > > change.  If anyone has a good tutorial written could you please post
> > > it.  Also, What does this line mean ?
> > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>
> > Seehttp://httpd.apache.org/docs/2.2/mod/mod_env.html. I suggest you

Graham Dumpleton

unread,
Nov 11, 2008, 12:04:57 AM11/11/08
to Django users
Are you setting up Apache to serve your Django static media as
instructions indicate you to do?

If you have, have you put in the direct URL to where the static media
should hosted into your browser to see if it works? Have you then
compared that URL to what HTML pages are trying to access for the
same?

Graham
Reply all
Reply to author
Forward
0 new messages