Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Python中瓶子上没有提供静态文件_Javascript_Python_Css_Bottle - Fatal编程技术网

Javascript Python中瓶子上没有提供静态文件

Javascript Python中瓶子上没有提供静态文件,javascript,python,css,bottle,Javascript,Python,Css,Bottle,我正在尝试设置一个应用程序,它接受一个模板HTML文件并实时修改它。它在一定程度上是有效的,但是页面上的图像和CSS没有被提供,当请求它们时,控制台上有HTTP 500错误 这是我的目录结构 Server/ assets/ css/ img/ jquery.css kickstart.css zellner.css js/ jquery.

我正在尝试设置一个应用程序,它接受一个模板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')
@错误(403)
def error403(错误):
返回静态_文件(“403.html”)
@错误(404)
def error404(错误):
返回静态_文件(“404.html”)
@误差(500)
def error500(错误):
返回静态_文件(“500.html”)
@路由('资产/')
def服务器_静态(文件路径):
返回静态文件(filepath,root='assets')
在我的html文件中,文件链接如下:

<script type="text/javascript" src="assets/js/jquery.snippet.min.js"></script>

这可能是由于assets/中的子目录中存在静态数据造成的吗?还是我完全误解了如何使用静态文件

这是我在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>
[07/May/2012 10:51:05]“GET/tempus/23 HTTP/1.1”200 4501处理请求时出现严重错误:/tempus/assets/js/jquery.snippet.min.js
我不明白为什么要路由到/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

您必须将文件的完整路径放在root=中,这取决于程序运行的位置。
看看这个:

您的@route装饰器不适用于静态服务


它应该读为@route('/assets/')

This。路径相对于工作目录,而不是作为服务器的python模块
root=os.path.join(os.path.dirname(_文件,_),‘static’)
为我做了这件事!回答正确!谢谢