Skip to main content

spring-like request_mapping for django.

Project description

Make urlpatterns more human-readable.

Requirements

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

Install and update using pip:

pip install -U  django-request-mapping

A Simple Example

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

Full Example

https://github.com/sazima/django-request-mapping/tree/master/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.12.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

django_request_mapping-0.0.12-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file django-request-mapping-0.0.12.tar.gz.

File metadata

  • Download URL: django-request-mapping-0.0.12.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for django-request-mapping-0.0.12.tar.gz
Algorithm Hash digest
SHA256 7581fdfcac3973659943442f1466753a9b852290acc62604b16a0fa3ca7128ac
MD5 f58d357a9fe8519df04f45fbc5bd7c3a
BLAKE2b-256 2ce96afe9639a6fc9b08923ba6cc9b9a3adc4eabb67cbef2692073bbf5b1a517

See more details on using hashes here.

File details

Details for the file django_request_mapping-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: django_request_mapping-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for django_request_mapping-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 56564c75bd622570564ebf328a73068abf078277c29f17c85625273a53d7cd9c
MD5 e37023dc63f959921a4cd2e7e556c0c3
BLAKE2b-256 238143ecc090bd02cdd8c38202bdeb3fa597282a734c321f7911cbf53252f22e

See more details on using hashes here.

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