views:

113

answers:

1

So every web.py tutorial I've seen includes this line:

urls = (
    '/', 'index',
)

And then, later on, the index class is defined with a GET function and so on. My problem is, this doesn't work. Using the code above, I get a 404 error. Using the following mapping works:

urls = (
    '/.*', 'index',
)

But that's going to catch, at least at first, every single possible URL, and I want only an access to the domain root to be handled by "index." Halp?

Some basic info:

Python 2.6, web.py 0.3, Apache 2.2 with mod_wsgi

Not sure what else would be useful, so if there is something important I can add (the VirtualHost from Apache, maybe?) please ask and I'll add it here.

EDIT: Including my Apache VirtualHost config:

<VirtualHost *:80>
    ServerName dd.sp4.us
    DocumentRoot /home/steve/www/nov2010/public/
    ErrorLog /home/steve/www/nov2010/log/error.log
    CustomLog /home/steve/www/nov2010/log/access.log combined

    WSGIScriptAlias / /home/steve/www/nov2010/app
    Alias /static /home/steve/www/nov2010/public

    <Directory /home/steve/www/nov2010/app>
        SetHandler wsgi-script
        Options ExecCGI
    </Directory>

    AddType text/html .py

    <Location />
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_URI} !^/static
        RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
        RewriteRule ^(.*)$ code.py/$1 [PT]
    </Location>
</VirtualHost>
+2  A: 

For background read:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

Presuming you only have the one WSGI application to be mounted at root of site and only static files or other resources are under /static, then instead of:

WSGIScriptAlias / /home/steve/www/nov2010/app
Alias /static /home/steve/www/nov2010/public

<Directory /home/steve/www/nov2010/app>
    SetHandler wsgi-script
    Options ExecCGI
</Directory>

AddType text/html .py

<Location />
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/static
    RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
    RewriteRule ^(.*)$ code.py/$1 [PT]
</Location>

use:

Alias /static /home/steve/www/nov2010/public

WSGIScriptAlias / /home/steve/www/nov2010/app/code.py

<Directory /home/steve/www/nov2010/app>
Order allow,deny
Allow from all
</Directory>

You are mixing up multiple ways of configuring mod_wsgi which shouldn't be used together.

If your requirements are something else, you are going to have to be clearer about what you want to happen.

Graham Dumpleton
Works perfectly. And even better than that, makes perfect sense, too. Thanks!!
Steve Paulo