Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Templates 获取瓶子中请求的当前URL_Templates_Bottle - Fatal编程技术网

Templates 获取瓶子中请求的当前URL

Templates 获取瓶子中请求的当前URL,templates,bottle,Templates,Bottle,我想在我的基本模板中放入一些代码块,但只有在request.route为“/page”时才可以 我试着添加一些,比如: % if request.route == "/home": <a class="pure-button" id="showWishboneAddForm"> <i class="fa fa-plus-circle"></i> Dodaj tuleję </a> % end %if request.route==

我想在我的基本模板中放入一些代码块,但只有在request.route为“/page”时才可以

我试着添加一些,比如:

% if request.route == "/home":
  <a class="pure-button" id="showWishboneAddForm">
    <i class="fa fa-plus-circle"></i> Dodaj tuleję
  </a>
% end
%if request.route==“/home”:
多达吉·图勒伊(Dodaj tuleję)
%结束
但后来我发现了一个错误:
namererror(“未定义名称‘请求’”)


我不想将
请求
参数添加到所有路由

您可以通过以下简单的*方式使请求在所有视图/模板上可用

from bottle import view, request, template, get
from functools import partial
view = partial(view, request=request)
template = partial(template, request=request)    

#now lets use it
@get("/")
@view("mytpl.tpl")
def index():
    return {"msg": "Cool stuff!"}

我希望它能满足您的需要

谢谢!此外,我还发现了类似这样的内容:
SimpleTemplate.defaults[“request”]=request
您不应该这样做,因为这不是线程安全的。模板中可能有一个页面包含错误的“request”变量。@Augustinalville-
request
对象使用
thread.local
,因此应该可以。我确定不是,请进行测试。