I'm working with Flask 1.0.2 and I'm trying to route the two URLs to the same function.
My two URLs that I want to use the same function are:
/alerts/<string:first_property>/<string:first_value>/<string:manufacturer_value>
/alerts/<string:first_property>/<string:first_value>/<string:manufacturer_value>/<string:category_value>
I have tried setting the value of category_value to None in the function, but when trying to access the first URL I receive this error.
    filters['Category'] = category_number[category_value]
KeyError: None
Full code:
@app.route('/alerts/<string:first_property>/<string:first_value>/<string:manufacturer_value>', methods=['GET'])
@app.route('/alerts/<string:first_property>/<string:first_value>/<string:manufacturer_value>/<string:category_value>', methods=['GET'])
def category(first_property,first_value, manufacturer_value,category_value=None):
    kpi = 'kpi'
    hanaview = 'hanaview'
    filters = {'CalYear': 2015, 'CalQuarter': (1, 3)}
    filters['Category'] = category_number[category_value]
    #print(category_number[category_value])
    filters['ManufacturerDescription'] = manufacturer_value
    progression = ['CategoryDescription','SubcategoryDescription']
    if first_property == 'Hub':
        progression.insert(0,'Country')
    if first_property == 'Division':
        progression.insert(0, 'Hub')
    alert_tree = get(kpi, hanaview, filters, progression, first_property, first_value)
    tree = alert_tree.get_tree()
    return jsonify(tree), status.HTTP_201_CREATED
 
    