【问题标题】:Wrong path for statics when Dynamic routing a template Bottle动态路由模板Bottle时静态路径错误
【发布时间】:2015-02-12 22:08:32
【问题描述】:

我正在使用瓶子框架,我发现了这个问题。

当我使用静态路径时,一切正常,但是当我使用动态路由时,.css 和 .js 的路径发生变化,并且没有找到文件错误。

我有这个方法:

@get('/mod_user/<id_user>')
def mod_user(id_user):
    user = driver.get_user_by_id(id_user)
    return template('moduser', user=user)

我有一个用于静态文件的文件,它适用于“/contact”等路径:

@route('/static/:path#.+#', name='static')
def static(path):
    return static_file(path, root='static')

问题来了,因为添加 /mod_user 到静态搜索路径:

http://10.141.0.63:8080/mod_user/static/css/formularioadd.css

我尝试以多种方式更改静态路径,但没有任何效果。

有什么想法吗?

谢谢大家

【问题讨论】:

  • 我自己回答,为了避免这个问题,如果您从主体模板扩展所有文件,则必须确保您的静态文件具有绝对路径。

标签: python dynamic routes bottle


【解决方案1】:

你没有匹配/mod_user/static的路由。

(另外,您不必要地使用正则表达式。)

你尝试过这样的事情吗?

@route('/mod_user/static/<path:path>')
def static(path):
    ...

【讨论】:

  • 是的,我解决了,问题是您必须将 css 文件绝对放在通用模板中。反正你
猜你喜欢
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 2016-06-05
  • 1970-01-01
  • 2021-11-18
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多