我使用引導程式的默認模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home Page</title>
<LINK href="{{ url_for('static', filename='reset.css') }}"
rel="stylesheet">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<LINK href="{{ url_for('static', filename='custom.css') }}"
rel="stylesheet">
<link rel="shortcut icon"
href="#">
</head>
<body>
{{
components.main_navigation_bar()
}}
{% block content %} {%
endblock %}
{{ components.main_footer() }}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X 965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH 8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV 2 9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3 MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</html>
從我的 level_0_01_global_macros.html
{% macro apa_reference_citation(content) %}
<div class="container px-5 mb-4 apa_reference">
{{ content }}
</div>
{%- endmacro %}
現在我將默認模板和宏匯入到我的 home_page.html
{% extends "level_0_00_default_layout.html" %}
{% import 'level_0_01_global_macros.html' as components %}
現在我正在使用宏在 home_page.html 上寫一個參考 - 這輸出到我的瀏覽器服務器 127.0.0.1:5000/
{% block content %}
{{ components.apa_reference_citation('
Achdut, N., & Refaeli, T. (2020).
Unemployment and Psychological Distress among Young People during the COVID-19 Pandemic:
Psychological Resources and Risk Factors. International journal of environmental research and public
health,
17(19), 7163. https://doi.org/10.3390/ijerph17197163
') }}
{% endblock content %}
我想在“https://doi.org/10.3390/ijerph17197163”部分添加指向上述引文的鏈接。因此,在此輸出給某人的網頁上,可以單擊該引文鏈接并轉到具有該研究的網站。
我嘗試過的事情:
-我嘗試<a></a>在鏈接周圍插入一個標簽,它只是在使用“”或“時輸出一個字串。
-reddit 上的某個人告訴我把這個放在<a href='https://doi.org/10.3390/ijerph17197163'>https://doi.org/10.3390/ijerph17197163</a>輸出是一條錯誤訊息,上面寫著“ "jinja2.exceptions.TemplateSyntaxError: expected token ',' got 'https'”
- 我找不到從上面的輸出中插入任何變數或元素的轉義。
- 我確實看到我能夠將整個宏包裝在一個<a></a>標簽中,但我需要鏈接特定的單詞而不是整個參考或段落。
-我查看了 Jinja 檔案,找不到任何可以回答我問題的內容。我對此很陌生,所以如果它在那里并且我沒有看到它,我深表歉意。
- 我瀏覽了類似的問題,但我看到的唯一類似的問題是宏本身上的問題,而不是在使用它時,它們只針對一個元素,如表單或影像。
-我在reddit上發帖:
有沒有辦法做到這一點?先感謝您
uj5u.com熱心網友回復:
您可以將其嵌入到call中,而不是將參考的全部內容作為引數傳遞。通過這種方式,您也可以在代碼中將錨點用作 html。
level_0_01_global_macros.html
{% macro apa_reference_citation() -%}
<div class="container px-5 mb-4 apa_reference">
{{ caller() }}
</div>
{% endmacro -%}
home_page.html
{% extends 'level_0_00_default_layout.html' %}
{% import 'level_0_01_global_macros.html' as components %}
{% block content %}
{% call components.apa_reference_citation() -%}
Achdut, N., & Refaeli, T. (2020).
Unemployment and Psychological Distress among Young People during the COVID-19 Pandemic:
Psychological Resources and Risk Factors. International journal of environmental research and public health,
17(19), 7163. <a href="https://doi.org/10.3390/ijerph17197163">https://doi.org/10.3390/ijerph17197163</a>
{% endcall -%}
{% endblock content %}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/488520.html
