文件结构
Package: main
---static
--css
--bootstrap.min.css
--style.css
--js
--img
-- main.py
--main.tpl
run main.py后加载出main.tpl页面,在main.tpl页面需要引用css静态文件
具体代码如下:
from bottle import get, post, request, route, run, template, static_file
import os
@get('/main')
def index():
currentPath=os.path.dirname(os.path.realpath(__file__)) #获取当前路径
print currentPath
return template(currentPath+r'/main')
@route('/main/static/css/<bootstrap>')
def server_static(bootstrap):
return static_file(bootstrap, root='./main/static/css')
run(host='localhost', port=8081)
请多指教!
Package: main
---static
--css
--bootstrap.min.css
--style.css
--js
--img
-- main.py
--main.tpl
run main.py后加载出main.tpl页面,在main.tpl页面需要引用css静态文件
具体代码如下:
from bottle import get, post, request, route, run, template, static_file
import os
@get('/main')
def index():
currentPath=os.path.dirname(os.path.realpath(__file__)) #获取当前路径
print currentPath
return template(currentPath+r'/main')
@route('/main/static/css/<bootstrap>')
def server_static(bootstrap):
return static_file(bootstrap, root='./main/static/css')
run(host='localhost', port=8081)
请多指教!