Skip to content
Myr

Fix flask issue #338

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Give POST its own url_rule to avoid TypeError.

authored by Jim Rollenhagen · committed by Jim Rollenhagen · parent 11c7b1d · Browse files · 1 file+4 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−2 removed

  • other:+4 added−2 removed

1 file+4 added−2 removed

modified:docs/views.rst+4 added-2 removed
208 unmodified lines
209and explicitly mentioning the methods for each::210211 user_view = UserAPI.as_view('user_api')212 app.add_url_rule('/users/', defaults={'user_id': None},213 view_func=user_view, methods=['GET', 'POST'])213 view_func=user_view, methods=['GET',])214 app.add_url_rule('/users/', view_func=user_view, methods=['POST',])215 app.add_url_rule('/users/<int:user_id>', view_func=user_view,216 methods=['GET', 'PUT', 'DELETE'])217218If you have a lot of APIs that look similar you can refactor that
1 unmodified line
220221 def register_api(view, endpoint, url, pk='id', pk_type='int'):222 view_func = view.as_view(endpoint)223 app.add_url_rule(url, defaults={pk: None},223 view_func=view_func, methods=['GET', 'POST'])224 view_func=view_func, methods=['GET',])225 app.add_url_rule(url, view_func=view_func, methods=['POST',])226 app.add_url_rule('%s<%s:%s>' % (url, pk), view_func=view_func,227 methods=['GET', 'PUT', 'DELETE'])228229 register_api(UserAPI, 'user_api', '/users/', pk='user_id')