I am setting a url endpoint with the following:
manager.py
from xxx import ContactAPI
from xxx.models import Contact
# self.app is my Flask app
# self.session is SQLAlchemy Session
api_name = 'contact'
instance_endpoint = '/%s/<int:instid>' % api_name
methods = ['GET']
api_view = ContactAPI.as_view(api_name, self.session,
Contact, app)
self.app.add_url_rule(instance_endpoint, methods=methods,
defaults={'instid': None},
view_func=api_view)
And overriding get() in my ContactAPI class:
views.py
from flask.views import MethodView
class ContactAPI(MethodView):
def __init__(self, session, model, app, *args, **kwargs):
super(ContactAPI, self).__init__(*args, **kwargs)
def get(self, instid):
print instid
When I hit the URL /contact/1 I get instid printed as None.
When I remove the defaults={'instid': None}, line from manager.py, I get instid printed as 1.
Why is having the defaults line in my call to add_url_rule overriding what I'm putting in my URL?