- 論壇徽章:
- 1
|
web中有css,images,js文件時候,就要顯示的告訴cherrypy,不然會出錯
假設(shè)文件存放如下:
- web\
-
----view\
-
----css
-
----images
-
----scripts
則配置文件web.conf如下:
- [/]
-
tools.staticdir.root = '/path/to/web/view'
-
[/css]
-
tools.staticdir.on = True
-
tools.staticdir.dir = 'css'
-
-
[/scripts]
-
tools.staticdir.on = True
-
tools.staticdir.dir = 'scripts'
-
[/images]
-
tools.staticdir.dir = 'images'
源文件相應(yīng)改變:
- cherrypy.quickstart(Root(),'/','web.conf')
順便一提,在使用mako的
- tmpl = lookup.get_template('detail.tpl')
-
return tmpl.render_unicode()
時,detail.tpl文件中必須有# -*-encoding:utf-8 -*- 標(biāo)記,以標(biāo)示文檔為utf-8編碼,不然會出現(xiàn) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 712: ordinal not in range(128) 而且get_template函數(shù)中的參數(shù)即文件名不能有特殊字符如de_tail.tpl就不行。
|
|