# -*- coding: latin1 -*-
import cherrypy, os
def login_screen(from_page='..', username='', error_msg=''):
return """
<html>
<link rel="stylesheet" type="text/css" href="/static/css/
site.css"></link>
<body>
<form method=post action=do_login>
<center>
<table>
<tr>
<td></td>
<td>%s</td>
</tr>
<tr>
<td><b>Utilizador:</b></td>
<td><input type=text class='TextField' name=username
value='%s'></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type=password class=TextField
name=password></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=Login></td>
</tr>
</table>
</center>
</form>
</body>
</html>
""" % (error_msg,username)
def check_login_and_password(login, password):
pass
class Root:
@cherrypy.expose
def index(self):
return 'Hello World'
base_path = os.path.dirname(os.path.abspath(__file__))
cherrypy.config.update({
'server.thread_pool': 0,
'tools.sessions.on': True,
'tools.session_auth.on': True,
'tools.session_auth.check_username_and_password':
check_login_and_password,
'tools.session_auth.login_screen': login_screen,
'tools.sessions.storage_type': 'file',
'tools.sessions.storage_path': 'sessions'
})
conf = {
'/static/css/site.css': {
'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(base_path, 'static',
'css', 'site.css') }
}
import pprint
cherrypy.log(pprint.pformat(conf))
cherrypy.tree.mount(Root(), config=conf)
cherrypy.log(os.path.join(base_path, 'static', 'css', 'site.css'))
cherrypy.server.quickstart()
cherrypy.engine.start()
The problem is that the login_screen() is not using the '/static/css/
site.css' style. If I use this url http://localhost:8080/static/css/site.css
I get html instead of the css contents:
<html>
<link rel="stylesheet" type="text/css" href="/static/css/
site.css"></link>
<body>
<form method=post action=do_login>
<center>
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td><b>Utilizador:</b></td>
<td><input type=text class='TextField' name=username
value=''></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type=password class=TextField
name=password></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=Login></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Am I doing something wrong or this is a known bug.
I'm using cherrypy 3.0.1 with gentoo linux, python 2.5.1 and firefox
2.0.0.4
Filipe Sousa