【发布时间】:2017-06-23 12:43:31
【问题描述】:
我正在构建一个购物车应用程序。我有应用程序的登录、注销和注册部分工作。当用户完成应用程序的注册部分时,他们将被重定向到当他们看到如下所示的项目选择时:
{% extends 'base.html' %}
{% block content %}
<h1>Gigi's Catering Menu</h1>
<form method="post">
<label>
<div><h2>Large Gourmet Meat & Cheese Tray</h2></div>
<p>
Fresh Roast Sirloin Beef, Baked Ham, and
Roasted Turkey with Swiss and
American Cheese<br>
Serves 20-25 people
</p>
Price would be $54.99 Per Tray
<input type="hidden" name="unq_id" value="1">
<input type="hidden" name="product_name" value="Large Gourmet Meat & Cheese Tray">
<input type="hidden" name="price" value="54.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>GiGi's Signature Chicken Salad</h2></div>
<h3>Mini Croissants Tray Sold by the Dozen</h3>
Price would be per Dozen $26.99
<input type="hidden" name="unq_id" value="2">
<input type="hidden" name="product_name" value="Chicken Salad Mini Croissants Tray">
<input type="hidden" name="price" value="26.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<h3>Chicken Salad Sold by the Pound</h3>
Price would be per Pound $7.99
<input type="hidden" name="unq_id" value="3">
<input type="hidden" name="product_name" value="Chicken Salad Sold by the Pound">
<input type="hidden" name="price" value="7.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Relish Tray</h2></div>
<p>
Carrot Sticks, Celery Sticks, Olives, and
Butterchip Pickles Served with Ranch Veggie Dip<br>
Serves 10-15 people
</p>
Price would be $19.99 Per Tray
<input type="hidden" name="unq_id" value="4">
<input type="hidden" name="product_name" value="Relish Tray">
<input type="hidden" name="price" value="19.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Fruit Tray</h2></div>
<p>Strawberries, Grapes, Pineapple, Honey Dew, Cantaloupe, and
Watermelon (when in season)<br>
Serves 15-20 people
</p>
Price would be $39.99 Per Tray
<input type="hidden" name="unq_id" value="5">
<input type="hidden" name="product_name" value="Fruit Tray">
<input type="hidden" name="price" value="39.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Toasted Ravioli</h2></div>
<p>Served with Marinara Sauce<br>
Serves 15-20 people
</p>
Price would be $19.99 Per Tray
<input type="hidden" name="unq_id" value="6">
<input type="hidden" name="product_name" value="Toasted Ravioli">
<input type="hidden" name="price" value="19.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>3 Foot Party Sub</h2></div>
<p>Fresh Roasted Sirloin Beef, Baked Ham, Hard
Salami, Swiss Cheese, American Cheese, and
Green Leaf Lettuce<br>
Serves 10-15 people
</p>
Price would be $39.99 Each
<input type="hidden" name="unq_id" value="7">
<input type="hidden" name="product_name" value="3 Foot Party Sub">
<input type="hidden" name="price" value="39.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Wing Tray</h2></div>
<p>You can have your Wing Tray as a Buffalo Wing or Wild Wing. You can
provide further information in the bottom section of this menu.<br>
Serves 15-20 people and costs about $19.99 Per Tray
</p>
Wing Tray - Select This: Buffalo Wing
<input type="hidden" name="unq_id" value="8">
<input type="hidden" name="product_name" value="Buffalo Wing Tray">
<input type="hidden" name="price" value="19.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<br><br>
Wing Tray - Select This: Wild Wing
<input type="hidden" name="unq_id" value="9">
<input type="hidden" name="product_name" value="Wild Wing Tray">
<input type="hidden" name="price" value="19.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>GiGi's Fresh Made Potato Chips</h2></div>
<p>Served with a French Onion Dip Tray<br>
Serves 10-15 people
</p>
Price would be $16.99 Per Tray
<input type="hidden" name="unq_id" value="10">
<input type="hidden" name="product_name" value="Potato Chips Served with French Onion Dip Tray">
<input type="hidden" name="price" value="16.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>GiGi's Mini Sweet rolls</h2></div>
<ul>
<li>Ham & Swiss Cheese</li>
<li>Fresh Roasted Sirloin Beef & Cheddar Cheese</li>
<li>Fresh Roasted Turkey & Provel Cheese</li>
<li>$21.99 Per Dozen
</ul>
Price would be Ham and Swiss
<input type="hidden" name="unq_id" value="11">
<input type="hidden" name="product_name" value="Sweet Rolls Ham and Swiss By The Dozen">
<input type="hidden" name="price" value="21.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<br>
Price would be Roast Beef and Cheddar Cheese
<input type="hidden" name="unq_id" value="12">
<input type="hidden" name="product_name" value="Sweet Rolls Roast Beef and Cheddar Cheese By The Dozen">
<input type="hidden" name="price" value="21.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<br>
Price would be Roasted Turkey and Provel Cheese
<input type="hidden" name="unq_id" value="13">
<input type="hidden" name="product_name" value="Sweet Rolls Roasted Turkey and Provel Cheese By The Dozen">
<input type="hidden" name="price" value="21.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>GiGi's Brownie Tray</h2></div>
<p>Serves 10-15 people</p>
Price would be $19.99 Per Tray
<input type="hidden" name="unq_id" value="14">
<input type="hidden" name="product_name" value="GiGi's Brownie Tray">
<input type="hidden" name="price" value="19.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Variety Wrap Platter</h2></div>
<p>Our Variety Wrap Platters come with Chicken Caesar, Turkey Ranch, and
Buffalo Chicken Tender w/Ranch
</p>
Price would be $25.99 Per Tray
<input type="hidden" name="unq_id" value="15">
<input type="hidden" name="product_name" value="Variety Wrap Platter">
<input type="hidden" name="price" value="25.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>Tea Sandwiches</h2></div>
<p>GiGi's Signature Chicken Salad or Tuna Salad on Wheatberry Bread<br>
Serves 10-15 people<br>
$25.99 Per Tray</p>
Price would be Chicken Salad
<input type="hidden" name="unq_id" value="16">
<input type="hidden" name="product_name" value="Tea Sandwiches with Chicken Salad on Wheatberry Bread">
<input type="hidden" name="price" value="25.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<br>
Price would be Tuna Salad
<input type="hidden" name="unq_id" value="17">
<input type="hidden" name="product_name" value="Tea Sandwiches with Tuna Salad on Wheatberry Bread">
<input type="hidden" name="price" value="25.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<label>
<div><h2>GiGi's Cookie Tray</h2></div>
<p>Our Cookie Trays come with Chocolate Chip and Sugar Cookies<br>
Serves 10-20 people</p>
Price would be $16.99 Per Tray
<input type="hidden" name="unq_id" value="18">
<input type="hidden" name="product_name" value="Gigi's Cookie Tray">
<input type="hidden" name="price" value="16.99">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</label>
<br>
<hr style="height:0px">
<br>
<label>
<div><h1>GiGi's Lunch Boxes</h1></div>
<ul style="list-style-type:disc">
<li><h2>Choice of Meat:</h2></li>
<ul style="list-style-type:square">
<li>Fresh Roasted Sirloin Beef</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="100">
<input type="hidden" name="product_name" value="Lunch Box: Meat - Roast Beef">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Fresh Ham</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="101">
<input type="hidden" name="product_name" value="Lunch Box: Meat - Ham">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Fresh Roasted Turkey</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="102">
<input type="hidden" name="product_name" value="Lunch Box: Meat - Roasted Turkey">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Chicken Salad</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="103">
<input type="hidden" name="product_name" value="Lunch Box: Chicken Salad">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Tuna Salad</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="104">
<input type="hidden" name="product_name" value="Lunch Box: Tuna Salad">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</ul>
<li><h2>Choice of Cheese:</h2></li>
<ul style="list-style-type:square">
<li>Cheddar Cheese</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="110">
<input type="hidden" name="product_name" value="Lunch Box: Cheese - Cheddar">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Swiss Cheese</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="111">
<input type="hidden" name="product_name" value="Lunch Box: Cheese - Swiss">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Provolone Cheese</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="112">
<input type="hidden" name="product_name" value="Lunch Box: Cheese - Provolone">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Pepper Jack Cheese</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="113">
<input type="hidden" name="product_name" value="Lunch Box: Cheese - Pepper Jack">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</ul>
<li><h2>Choice of Bread:</h2></li>
<ul style="list-style-type:square">
<li>Wheatberry</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="120">
<input type="hidden" name="product_name" value="Lunch Box: Bread - Wheatberry">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Hoagie</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="121">
<input type="hidden" name="product_name" value="Lunch Box: Bread - Hoagie">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Pretzel</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="122">
<input type="hidden" name="product_name" value="Lunch Box: Bread - Pretzel">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Croissant</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="123">
<input type="hidden" name="product_name" value="Lunch Box: Bread - Croissant">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</ul>
<li><h2>Choice of a Side Item:</h2></li>
<ul style="list-style-type:square">
<li>Potato Salad</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="130">
<input type="hidden" name="product_name" value="Lunch Box: Side - Potato Salad">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Pasta Salad</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="131">
<input type="hidden" name="product_name" value="Lunch Box: Side - Pasta Salad">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Potato Chips</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="132">
<input type="hidden" name="product_name" value="Lunch Box: Side - Potato Chips">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</ul>
<li><h2>Choice of a Dessert:</h2></li>
<ul style="list-style-type:square">
<li>Brownie</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="140">
<input type="hidden" name="product_name" value="Lunch Box: Dessert - Brownie">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
<li>Cookie</li>
<input type="checkbox" name="chkbox" value="True"> Select this Item
<input type="hidden" name="unq_id" value="141">
<input type="hidden" name="product_name" value="Lunch Box: Dessert - Cookie">
Qty: <input type="text" name="qty" id="q01" value="{{qty}}">
</ul>
</ul>
<p>All of our Lunch Box meals come with Lettuce & Tomato.</p>
<p>A Whole Meal In a Box! For $9.49 Each</p>
</label>
<br>
<hr style="height:0px">
<br>
<label>
<div>Additional Comments and/or Special Requests</div>
<textarea name="body">{{body}}</textarea>
</label>
<div class="error">{{ error }}</div>
<input type="button" value="submit">
<input type="reset">
</form>
{% endblock %}
下面会列出处理菜单和购物车的功能以及其他必要的功能,但为简单起见,我只在下面发布主页、菜单和购物车功能:
class MainPageHandler(Handler):
def render_form(self):
""" Render a page with what the customer has ordered """
t = jinja_env.get_template("mainpage.html")
response = t.render()
self.response.out.write(response)
def get(self):
self.render_form()
class MenuHandler(Handler):
""" This will be a function to allow the user to create their specific
order from the selected items. """
def render_form(self, unq_id="", product_name="", price="", qty="", body=""):
""" Render the new post form with or without an error, based on parameters """
t = jinja_env.get_template("menu.html")
response = t.render(unq_id=unq_id, product_name=product_name, price=price, qty=qty, body=body)
self.response.out.write(response)
def get(self):
self.render_form()
def post(self):
unq_id = self.request.get("unq_id")
product_name = self.request.get("product_name")
price = self.request.get("price")
qty = self.request.get("qty")
body = self.request.get("body")
# create new temporary order object and store it in the database
tmp_order = Tmp_Order(unq_id=unq_id,
product_name=product_name,
price=price,
qty=qty,
body=body)
tmp_order.put()
self.redirect('/cart')
class CartHandler(Handler):
""" This will be a function to allow the user to see what they have ordered
from their selections within the menu. """
def update(self, item):
if item.unq_id not in self.content:
self.content.update({item.unq_id: item})
return
for k, v in self.content.get(item.unq_id).items():
if k == 'unq_id':
continue
elif k == 'qty':
total_qty = v.qty + item.qty
if total_qty:
v.qty = total_qty
continue
self.remove_item(k)
else:
v[k] = item[k]
def get_total(self):
return sum([v.price * v.qty for _, v in self.content.items()])
def get_num_items(self):
return sum([v.qty for _, v in self.content.items()])
def remove_item(self, key):
self.content.pop(key)
def render_form(self, item_list=""):
# render the page
t = jinja_env.get_template("cart.html")
response = t.render(item_list = item_list)
self.response.out.write(response)
def get(self):
self.render_form()
def post(self):
self.redirect('/checkout', unq_id=unq_id, product_name=product_name, price=price, qty=qty, body=body)
我在运行应用程序时可以追溯信息,但我仍在为此苦苦挣扎。该信息是在 Python 2.7、Google App Engine 和 Jinja2 环境中编写的。任何和所有的帮助将不胜感激。
【问题讨论】:
-
你能发布回溯吗?它会帮助显示在哪里看?
-
我进行了回溯,并没有收到任何错误。很抱歉,我无法提供进一步的帮助。
-
重新考虑。回溯可以以微妙的方式提供信息。
标签: python html google-app-engine jinja2