Jhorra Jhorra - 1 year ago 126
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 Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download