class RespondersAPI(MethodView):
# some class based view to do restful services
...
#now we have url maps here
users_api = RespondersAPI.as_view('users_api', userlevel=1)
admin_mod.add_url_rule("/user/uid/<objectid:user_id>",
view_func = users_api,
methods=["PUT", "DELETE"])
admin_mod.add_url_rule("/user",
defaults={'page': 1},
view_func = users_api,
methods=["GET"])
admin_mod.add_url_rule("/user/page/<int:page>",
view_func = users_api,
methods=["GET"])
admin_mod.add_url_rule("/user/new",
view_func = users_api,
methods=["POST"],)
As you can see from above, the problem is that one can't reach the 4th routing rule. the objectid converter is what here's whats going on:
>>> url_for('.users_api', page=1)
'/admin/user'
>>> url_for('.users_api', page=2)
'/admin/user/page/2'
>>> url_for('.users_api', user_id=users[0].id)
'/admin/user?user_id=521781f4fe8974125cef5ea9' # not what I expected
the objectid converter is the one from Armin Ronacher. I put some debug codes there and discovered this isn't even fired. I thought this has something to do with the order of creating url rules, so I tried declaring the url rule with objectid before all other rules are declared; however this doesn't help at all. What is wrong with my codes? here is current url map:
Map([
<Rule '/admin/user/new' (POST, OPTIONS) -> admin_mod.users_api>,
<Rule '/admin/user/uid/<user_id>' (PUT, OPTIONS, DELETE) -> admin_mod.users_api>,
<Rule '/admin/user/page/<page>' (HEAD, OPTIONS, GET) -> admin_mod.users_api>,
<Rule '/admin/user' (HEAD, OPTIONS, GET) -> admin_mod.users_api>,
... # and a bunch of rules ..
])