我正在尝试设置一个应用程序,它接受模板 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
这是我在 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')
在我的 html 文件中,文件链接如下:
<script type="text/javascript" src="assets/js/jquery.snippet.min.js"></script>
会不会是因为 statics 在 assets/的子目录中?还是我完全误解了如何使用 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>
我不明白为什么它会路由到/tempus/assets/...
有什么帮助吗?谢谢!
最佳答案
我在提供静态文件时也遇到了问题。这是我的解决方案:
@route('/static/:filename#.*#')
def send_static(filename):
return static_file(filename, root='./static/')
当您想访问静态文件时,例如。模板文件:
@route('/')
def index():
output = template('static/index.tpl')
return output
关于javascript - 静态文件未在 Python 中的 Bottle 上提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480037/