Flask 템플릿 엔진 예약어 변경
{{이것으로 무엇이 기쁠까라고 하면, 예를 들어 Vue.js를 사용하려고 하면 Vue.js도
}} {%환경
코드
다음의 2개의 코드로
%} {{ }} {{ 를 }}{%from flask import Flask
# Flaskのテンプレートエンジンであるjinja2のenvironmentを作成。
from jinja2 import Environment, PackageLoader, select_autoescape
jinja2_environment = Environment(
    loader=PackageLoader(__name__, 'templates'),
    autoescape=select_autoescape(['html', 'xml']),
    block_start_string    ='[%',   #元は {%
    block_end_string      ='%]',   #元は %}
    variable_start_string ='[[',   #元は {{
    variable_end_string   =']]'    #元は }}
)
app = Flask(__name__)
@app.route('/')
def root():
    # 作ったenvironmentを指定してテンプレートを取得
    template = jinja2_environment.get_template('index.html')
    # テンプレートをレンダリング
    return template.render(var1="hello")
if __name__ == '__main__':
    app.run()
%}<html>
  <body>
    [% if 1 > 0 %]
      [[ var1 ]]
    [% endif %]
  </body>
</html>
결과
main.py를 실행하고 http://localhost:5000/에 액세스하면

와입니다.
Reference
이 문제에 관하여(Flask 템플릿 엔진 예약어 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/fetaro/items/f62924e6875d8062e6a3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)