小编Cal*_*oth的帖子

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/...

有帮助吗?谢谢!

javascript css python bottle

9
推荐指数
1
解决办法
7570
查看次数

在Python 3.2上返回True时出现'语法错误'

我现在的脚本中有以下功能:

def _convert_time(p):
    """Converts a percentage into a date,
    based on current date."""

    # This is the number of years that we subtract from
    # the current date.
    p_year = pow(math.e, (20.344 * pow(p, 3) + 3)) - pow(math.e, 3)

    # Returns in YYYY-MM-DD format
    date_in_history = date.today() - timedelta(days=(p_year * 365)

    # Return to the control loop
    return True
Run Code Online (Sandbox Code Playgroud)

我的所有函数都使用这个系统在最后返回True,这是因为有一个中心函数按顺序运行每个函数并检查它们是否在执行下一个函数之前正确运行.

但是,当我运行脚本时,在我输入值以启动脚本之前,我收到以下错误:

 File "C:\Users\Callum\Desktop\Tempus\TempusTest.py", line 59
 return True
      ^
Run Code Online (Sandbox Code Playgroud)

如果我在IDLE中创建一个返回True的函数并检查它,它工作正常,但由于某种原因它不在我的脚本中

你们有没有想过为什么会这样?

谢谢!:)

python return function

3
推荐指数
1
解决办法
3422
查看次数

标签 统计

python ×2

bottle ×1

css ×1

function ×1

javascript ×1

return ×1