My app has a Product model. Some Products have categories, some do not. In one of my pages I will have this:
{% if row.category %}
<a href="{{ url_for("details_with_category", category=row.category, title=row.title) }}"> row.prod_title</a>
{% else %}
<a href="{{ url_for("details_without_category", title=row.title) }}"> row.prod_title</a>
{% endif %}
The views that handles this are:
@app.route('/<category>/<title>', methods=['GET'])
def details_with_category(category, title):
....
return ....
@app.route('/<title>', methods=['GET'])
def details_without_category(title):
....
return ....
Both details_with_category and details_without_category do the exact same thing, just with different urls. Is there a way to combine the views into a single view that takes an optional argument when building the url?