-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
Add http method routing to urlpatterns
Problem
This doesn't work right now because the first url pattern will always resolve.
urlpatterns = [
path('pet', views.pet_list_view),
path('pet', views.pet_create_view),
]
I understand that we can solve this built in right now by routing on class methods.
urlpatterns = [
path('pet', views.PetView.as_view())
]
Also, it can be solved functionally by making our own "routing" view:
urlpatterns = [
path('pet', list_router(get=views.pet_list_view, post=views.pet_create_view),
]
It also seems like it would be nice if this "just worked" (or some other chosen syntax):
urlpatterns = [
path('pet', views.pet_list_view, methods=['GET'],),
path('pet', views.pet_create_view, methods=['POST']),
]
Request or proposal
request
Additional Details
forum thread
I found some prior tickets/conversation, but nothing really seems to suggest there's a blocker:
https://code.djangoproject.com/ticket/33780
https://code.djangoproject.com/ticket/2784
https://groups.google.com/g/django-developers/c/FQVrKXkYAig
I think this would be a nice addition to django especially for building some simple json apis. Looking at the UrlResolver code, it seems like not the type of code to try and implement as a "django app". Thoughts?
Implementation Suggestions
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status