所以我正在学习Jinja,并且我正在尝试使用扩展功能来覆盖具有新内容的块,但它无效。
home.html的
{% block mainBlock %}
<div id="newNewsCont">
<div id="leftCont">
<h2> Tesla Model 3 </h2>
<p> Model 3 combines real world range, performance, safety and spaciousness into a premium saloon that only Tesla can build. Our most affordable range yet, Model 3 acheives 215 miles of rage per charge while starting at only 35,000 USD before incentives. Model 3 is designed to attain the highest safety ratings in every category. </p>
</div>
<div id="rightCont">
<h2> Reliant Robin LX 3DR 0.9 </h2>
<p> 2 keys, cherry bomb exhaust, this car turns heads, just had brand new custom made interior fitted, with sound proofing under carpets, just had a full respray in renault 5 gt turbo pearl white </p>
</div>
</div>
{%endblock%}
我想用list.html
覆盖它{% extends "home.html" %}
{% block mainBlock %}
{% for item in cars %}
<li> {{ item }}</li>
{% endfor %}
{%endblock%}
server.py
import os
from flask import Flask, redirect, request, render_template
DATABASE = 'database.db'
app = Flask(__name__)
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
@app.route("/")
def home():
return render_template('list.html', msg = '')
@app.route("/ListCars")
def cars():
cars = ['tesla','reliant robin','Transit Van']
return render_template('list.html', cars = cars)
if __name__ == "__main__":
app.run(debug=True)
答案 0 :(得分:0)
如果您想保留home.html
的{{1}}设计:
list.html
list.html
如果这不是您想要的,那么请写出确切的问题,因为您的代码可以正常工作。