Jhorra Jhorra - 18 days ago 7
Python Question

Pass parameters to Flask application using Blueprints

I've looked at a handful of examples and tutorials, and as far as I can tell I have this correct. With the basic example below I get the following error:

TypeError: view() got an unexpected keyword argument 'id'


from flask import Blueprint, jsonify

location_app = Blueprint('location_app', __name__)

@location_app.route('/location/', defaults={'id': '0'})
@location_app.route('/location/<id>', methods=['GET'])
def view():
return "location view"

Answer

Your function have to take the variable of the url definition. Like this:

@location_app.route('/location/<id>', methods=['GET'])
def view(id):
    return "location view"
Comments