serving static with mod_python and django

1 view
Skip to first unread message

Baurzhan Ismagulov

unread,
Aug 26, 2006, 5:03:25 AM8/26/06
to django...@googlegroups.com
Hello,

I have the following lines in /etc/apache2/sites-available/default:

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

Alias /debian/ /mnt/sda1/ibr/debian/
<Directory /mnt/sda1/ibr/debian>
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>

<Location />
SetHandler python-program
...

When I try to access http://localhost/debian/ , I get Django's nice 404
error message. http://httpd.apache.org/docs/2.0/mod/core.html#location
says Location directives are processed after the Directory directives.
Can I have Django accessible at /, and other content still accessible
under other directories?

Thanks in advance,
Baurzhan.

Ivan Sagalaev

unread,
Aug 26, 2006, 5:19:20 AM8/26/06
to django...@googlegroups.com

Yes. You should Directories describing '/debian/' _after_ your
'<Location />' for this general rule not overwrite more specific ones.
Also you may have to convert your <Directories> to <Locations>

Baurzhan Ismagulov

unread,
Aug 26, 2006, 6:03:58 AM8/26/06
to django...@googlegroups.com
Hello Ivan,

thanks for your fast response!

On Sat, Aug 26, 2006 at 01:19:20PM +0400, Ivan Sagalaev wrote:
> > Can I have Django accessible at /, and other content still accessible
> > under other directories?
>
> Yes. You should Directories describing '/debian/' _after_ your
> '<Location />' for this general rule not overwrite more specific ones.
> Also you may have to convert your <Directories> to <Locations>

Hmm, I've converted <Directory /mnt/sda1/ibr/debian> to <Location
/debian> and put it after <Location />:

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Location />
SetHandler python-program
...
</Location>

Alias /debian /mnt/sda1/ibr/debian
<Location /debian>


Options Indexes FollowSymLinks
Order allow,deny
Allow from all

</Location>

<Location /debian> works if I comment out <Location />. If not, I get
the following response:

<pre>
Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 301, in HandlerDispatch
assert (type(result) == type(int())), \

AssertionError: Handler 'django.core.handlers.modpython' returned invalid return code.

</pre>

What is wrong here?

With kind regards,
Baurzhan.

Ivan Sagalaev

unread,
Aug 26, 2006, 6:26:28 AM8/26/06
to django...@googlegroups.com
Baurzhan Ismagulov wrote:
> Hmm, I've converted <Directory /mnt/sda1/ibr/debian> to <Location
> /debian> and put it after <Location />:
>
> DocumentRoot /var/www
> <Directory />
> Options FollowSymLinks
> AllowOverride None
> </Directory>
>
> <Location />
> SetHandler python-program
> ...
> </Location>
>
> Alias /debian /mnt/sda1/ibr/debian
> <Location /debian>
> Options Indexes FollowSymLinks
> Order allow,deny
> Allow from all
> </Location>
>
> <Location /debian> works if I comment out <Location />.

Oh I've forgot. It happens because Apache still passes all requests to
mod_python because of SetHandler set in the first rule. In subsequent
locations you have to also reset it with SetHandler None.

Baurzhan Ismagulov

unread,
Aug 26, 2006, 6:53:32 AM8/26/06
to django...@googlegroups.com
Ivan,

On Sat, Aug 26, 2006 at 02:26:28PM +0400, Ivan Sagalaev wrote:
> Oh I've forgot. It happens because Apache still passes all requests to
> mod_python because of SetHandler set in the first rule. In subsequent
> locations you have to also reset it with SetHandler None.

It worked, thanks much!

With kind regards,
Baurzhan.

Reply all
Reply to author
Forward
0 new messages