Make urlpatterns more human-readable.
django == 2.x
notice: I haven't tested it in version 3.x, so I don't know if it is supported, if there is any result, you can tell me
Install and update using pip:
pip install -U django-request-mapping
view.py
from django_request_mapping import request_mapping
@request_mapping("/user")
class UserView(View):
@request_mapping("/login/", method="post")
def login(self, request):
data = request.POST
return HttpResponse("ok")
@request_mapping("/signup/", method="post")
def signup(self, request):
return HttpResponse("ok")
@request_mapping("/<int:user_id>/role/")
def get_role(self, request, user_id):
return HttpResponse("ok")
@request_mapping("/<int:pk/", method='delete')
def delete(self, request, pk):
User.objects.filter(pk=pk).delete()
return HttpResponse("ok")
@request_mapping("/role")
class RoleView(View):
# ...
urls.py
from django_request_mapping import UrlPattern
urlpatterns = UrlPattern()
urlpatterns.register(UserView)
urlpatterns.register(RoleView)
and request urls are:
post: http://localhost:8000/user/login/
post: http://localhost:8000/user/signup/
get: http://localhost:8000/user/1/role/
delete: http://localhost:8000/user/1/
# ...
https://github.com/sazima/django-request-mapping/tree/master/example