Skip to main content

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

Metadata

Release files for django-request-mapping 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-request-mapping 0.0.12
File Size Uploaded
django-request-mapping-0.0.12.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-request-mapping 0.0.12
File Interpreter ABI Platform
django_request_mapping-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / django-request-mapping-0.0.12.tar.gz

Download URL django-request-mapping-0.0.12.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7581fdfcac3973659943442f1466753a9b852290acc62604b16a0fa3ca7128ac
BLAKE2b-256 checksum
How to use checksums
2ce96afe9639a6fc9b08923ba6cc9b9a3adc4eabb67cbef2692073bbf5b1a517
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_request_mapping-0.0.12-py3-none-any.whl

Download URL django_request_mapping-0.0.12-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56564c75bd622570564ebf328a73068abf078277c29f17c85625273a53d7cd9c
BLAKE2b-256 checksum
How to use checksums
238143ecc090bd02cdd8c38202bdeb3fa597282a734c321f7911cbf53252f22e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.11

2 release files

0.0.10

1 release file

0.0.9

3 release files

0.0.8

2 release files

0.0.7

3 release files

0.0.6

2 release files

0.0.5

3 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page