Skip to main content

make django url more comfortable.

Project description

make urlpatterns very easy to use.

Requirements

django == 2.x

Install

pip install django-request-mapping

QuickStart

  • view.py
from django_request_mapping import request_mapping


@request_mapping("/user")
class UserView(View):

    @request_mapping("/login/", method="post")
    def login(self, request, *args, **kwargs):
        return HttpResponse("ok")

    @request_mapping("/signup/", method="post")
    def register(self, request, *args, **kwargs):
        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)

run

python manage.py runserver

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/
# ...

Full Example

https://github.com/sazima/django-request-mapping/tree/master/request_mapping_example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-request-mapping-0.0.6.tar.gz (3.9 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page