我尝试引用此页面的另一页
<html>
<head>
</head>
<body>
<header>
<h1>Restaurants<h1>
</header>
{% for i in restaurants %}
<h5>
<a href= "*">
{{i.name}}
</a>
   
<a href = "*"> Edit </a>  
<a href = "*"> Delete </a>
</h5>
{% endfor %}
<a href = {{url_for('newRestaurant', restaurant_id = restaurant_id)}}> Create new restaurant </a>
</body>
</html>
这是我管理路由的Web服务器:
from flask import Flask, render_template, request, redirect, url_for, flash
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Restaurant, MenuItem
app = Flask(__name__)
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind = engine)
session = DBSession()
# Show all restaurants
.....
#Create new restaurants
@app.route('/restaurant/<int:restaurant_id>/new', methods = ['GET','POS'])
def newRestaurant(restaurant_id):
if request.method == 'POST':
new_Restaurant = Restaurant(name = request.form['new_restaurant_name'], restaurant_id = restaurant_id)
session.add(new_Restaurant)
session.commit()
#return "This page will be for making a new restaurant"
flash("new restaurant create")
return redirect(url_for('restaurants', restaurant_id = restaurant_id))
else:
return render('newRestaurant.html', restaurant_id = restaurant_id)
[我正在尝试转到我的创建餐厅页面:
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)
您不向Jinja模板中的restaurant_id
发送任何内容:
我解决了问题,这是如何解决
当我在restaurant_id=restaurant_id
定义下添加deleteMenuItem
时,它起作用。