|
Keerati Inochanon
unselfishly at gmail.com
Mon Mar 28 07:37:49 EST 2005
Hi,
I have been experimenting with vampire a little, and having problems
with module loading. I store handlers in $documentroot and some other
handlers in $documentroot/modules.
Here is my rough directory structure:
$documentroot:
index.html index.py login.html login.py modules register.html register.py
$documentroot/modules:
SessionManagement.py Settings.py UserManagement.py
In my login.py file, I import the module using vampire importModule mechanism:
config = vampire.loadConfig(__req__, ".vampire")
directory = config.get("Modules", "common")
UserManagement = vampire.importModule("UserManagement", directory)
SessionManagement = vampire.importModule("SessionManagement", directory)
--
In my UserManagement.py, I also need some stuff from
SessionManagement, so I also do:
config = vampire.loadConfig(__req__, ".vampire")
directory = config.get("Modules", "common")
SessionManagement = vampire.importModule("SessionManagement", directory)
Settings = vampire.importModule("Settings", directory)
--
My handler_html in login.py:
def handler_html(req, error=''):
if not os.path.exists(req.filename):
return apache.DECLINED
# Immediately redirect to the main page if session exists
session = SessionManagement.checkSession(req)
if session['isAuthorized'] and session['username']:
util.redirect(req, 'main.html')
message = ''
if error == 'invalid':
message = 'invalid username/password'
def renderTemplate(template, error):
template.result.content = error
html = open(req.filename, 'r')
template = HTMLTemplate.Template(renderTemplate, html.read())
html.close()
def handler_html(req, error=''):
if not os.path.exists(req.filename):
return apache.DECLINED
# Immediately redirect to the main page if session exists
session = SessionManagement.checkSession(req)
if session['isAuthorized'] and session['username']:
util.redirect(req, 'main.html')
message = '';
if error == 'invalid':
message = 'invalid username/password'
def renderTemplate(template, error):
template.result.content = error
html = open(req.filename, 'r')
template = HTMLTemplate.Template(renderTemplate, html.read())
html.close()
--
My httpd.conf:
<Directory "/home/www/testing">
PythonOption VampireDirectoryIndex index.html
SetHandler python-program
PythonHandler vampire
PythonPath 'sys.path'
# PythonOption VampireDefaultHandlers On
PythonDebug On
<Files ~ "^\.vampire">
Order allow,deny
deny from all
</Files>
</Directory>
--
When accessing login.html, I get this error:
Mod_python error: "PythonHandler vampire"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 585,
in _handler
module = _import(req,file)
File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 53, in _import
module = _moduleCache.importModule(name,directory,req)
File "/usr/lib/python2.3/site-packages/vampire/cache.py", line 181,
in importModule
execfile(file,module.__dict__)
File "/home/www/testing/login.py", line 9, in ?
UserManagement = vampire.importModule("UserManagement", directory)
File "/usr/lib/python2.3/site-packages/vampire/cache.py", line 306,
in importModule
return _moduleCache.importModule(name,path,req)
File "/usr/lib/python2.3/site-packages/vampire/cache.py", line 181,
in importModule
execfile(file,module.__dict__)
File "/home/www/testing/modules/UserManagement.py", line 8, in ?
config = vampire.loadConfig(__req__, ".vampire")
File "/usr/lib/python2.3/site-packages/vampire/config.py", line 263,
in loadConfig
return _configCache.loadConfig(req,name)
File "/usr/lib/python2.3/site-packages/vampire/config.py", line 198,
in loadConfig
req.vampire = { "config": {} }
AttributeError: 'NoneType' object has no attribute 'vampire'
--
I was wondering whether what I am doing is allowed or not. What should
I do to get around it? I am using vampire-1.5. Python, mod_python, and
vampire are still pretty new to me. Please let me know if you need any
further information. Thank you very much in advance.
Best regards,
Keerati
|