HTML模板

pygeoapi用途 Jinja 作为它的模板引擎来呈现HTML和 Flask 提供返回HTTP响应的API的路由路径。有关如何使用这些模块的完整详细信息,请参阅 Jinja documentation 以及 Flask documentation .

默认pyGeoapi配置为 server.templates 已注释掉并默认为pyGeoapi pygeoapi/templatespygeoapi/static 文件夹。要指向不同的模板配置集,您可以编辑您的配置:

server:
  templates:
    path: /path/to/jinja2/templates/folder # jinja2 template HTML files
    static: /path/to/static/folder # css, js, images and other static files referenced by the template

注: 静态文件夹的URL路径将始终是 /static 在已部署的pygeoapi web实例中。

templates文件夹应该模仿默认pygeoapi模板的相同文件名和结构。否则,您需要相应地修改 api.py

请注意,您只需要复制和编辑您感兴趣的更新模板。例如,如果您只对更新 landing_page.html 模板,然后创建唯一相同文件的您自己的版本。当pygeapi检测到正在使用自定义HTML模板时,它将在 server.templates.path 。如果它不存在,pyGeoapi将为给定的端点/requuest呈现默认HTML模板。

链接到HTML模板中的静态文件可以使用Jinja语法和 config['server']['url']

<!-- CSS example -->
<link rel="stylesheet" href="{{ config['server']['url'] }}/static/css/default.css">
<!-- JS example -->
<script src="{{ config['server']['url'] }}/static/js/main.js"></script>
<!-- Image example with metadata -->
<img src="{{ config['server']['url'] }}/static/img/logo.png" title="{{ config['metadata']['identification']['title'] }}" />