diff --git a/store/routes.py b/store/routes.py index 35dda03b8aa1f5974fa1f03b4ce908915f47135c..af7f173da9759fbc404eff65940a44c9921d7548 100644 --- a/store/routes.py +++ b/store/routes.py @@ -99,7 +99,7 @@ def item_sets(): return render_template("items.html", title="Item Sets", items=items) -@app.route("/item_page/item_<int:item_id>") +@app.route("/item_<int:item_id>") def item_page(item_id): item = get_item_by_id(item_id) if not item: @@ -108,7 +108,7 @@ def item_page(item_id): return render_template("item_page.html", item=item) -@app.route("/item_set_page/item_set_<int:item_id>") +@app.route("/item_set_<int:item_id>") def item_set_page(item_id): item = get_item_set_by_id(item_id) if not item: diff --git a/store/templates/item_page.html b/store/templates/item_page.html index 0eb54cac981bf2f2406daaa404e6b39eb3e33f00..d6fb4c7da682dbab70745d11089035297d16cf72 100644 --- a/store/templates/item_page.html +++ b/store/templates/item_page.html @@ -1,5 +1,4 @@ {%extends 'base.html' %} - {% block content %} {% block title %} Item Page | Antiques Online {% endblock %} <div> diff --git a/store/templates/items.html b/store/templates/items.html index de28bb762c783667d79e2bdae86ff8c27c53b24f..0dbf2ecb238de173e345b310b20a736a6b3d73bf 100644 --- a/store/templates/items.html +++ b/store/templates/items.html @@ -12,6 +12,9 @@ style="width: 200px; height: 200px;"> <!-- Set image size to ensure content is always fitting. --> <h2>{{ item.description }}</h2> <p>£{{ item.price }}</p> + <!-- Ternary operator to genericise the page to sets and items. Because of python shenanigans trying + to access an attribute that doesn't actually exist doesn't neccesarily cause an immediate exception and + so this can be used to check if the object is an item or item set.--> <a href="{{url_for('item_set_page', item_id = item.id) if item.items else url_for('item_page', item_id = item.id)}}">View Details</a>