如果js和css文件有不同的文件夹(在html文件中使用),这是所有项目中的常见情况,那么我们需要显式地分别为js和css目录内容提供服务。
有关详细信息,请参阅下面的代码:from bottle import route
from bottle import static_file
#Hosts html file which will be invoked from browser.
@route('/filesPath/')
def serve_static_file(staticFile):
filePath = '/path/to/your/static/file/'
return static_file(staticFile, filePath)
#host css files which will be invoked implicitly by your html files.
@route('/files_path/css/')
def serve_css_files(cssFile):
filePath = '/path/to/your/css/file/'
return static_file(cssFile, filePath)
# host js files which will be invoked implicitly by your html files.
@route('/files_path/js/')
def serve_js_files(jsFile):
filePath = '/path/to/your/jss/file/'
return static_file(jsFile, filePath)