Cal*_*oth 9 javascript css python bottle
我正在尝试设置一个应用程序,该应用程序采用模板HTML文件并对其进行实时修改.它在某种程度上起作用,但是页面上的图像和CSS没有被提供,并且在请求时控制台上存在HTTP 500错误.
这是我的目录结构
Server/
assets/
css/
img/
jquery.css
kickstart.css
zellner.css
js/
jquery.min.js
kickstart.js
style.css
tb_404.png
tbrun1.png
tbservers.png
403.html
404.html
500.html
appid
index.html
maintenance.html
server.log
server.py
Run Code Online (Sandbox Code Playgroud)
这是我在server.py中设置路由的方法:
@error(403)
def error403(error):
return static_file("403.html")
@error(404)
def error404(error):
return static_file("404.html")
@error(500)
def error500(error):
return static_file("500.html")
@route('assets/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='assets')
Run Code Online (Sandbox Code Playgroud)
在我的html文件中,文件链接如下:
<script type="text/javascript" src="assets/js/jquery.snippet.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
可能是因为静态资产位于资产的子目录中?或者我完全误解了如何使用static_file?
这是我在Python控制台上遇到的错误类型:
[07/May/2012 10:51:05] "GET /tempus/23 HTTP/1.1" 200 4501 <h1>Critical error while processing request: /tempus/assets/js/jquery.snippet.min.js</h1>
Run Code Online (Sandbox Code Playgroud)
我不明白它为什么路由到/ tempus/assets/...
有帮助吗?谢谢!
W0b*_*ble 10
我在提供静态文件方面也遇到了问题.这是我的解决方案:
@route('/static/:filename#.*#')
def send_static(filename):
return static_file(filename, root='./static/')
Run Code Online (Sandbox Code Playgroud)
当你想要访问静态文件时,例如.模板文件:
@route('/')
def index():
output = template('static/index.tpl')
return output
Run Code Online (Sandbox Code Playgroud)