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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-request-mapping-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d617d5c45f7a3e86dfa4bacb8d3a80db09837ac5ebd5ce89ffb55aa971063ef7 |
|
MD5 | 4c0883e64dd069ee4f275eff83f7d1f4 |
|
BLAKE2b-256 | 1a8f4e5ea68c43d06c8f398600be65c9b6d9849e30c606bdf5a7c8d62ddc8bec |
Close
Hashes for django_request_mapping-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 651c169933d13ce0812c675428c4f211a573bdb2c9f27af4ab95380edd72c92a |
|
MD5 | a831ca0a3d51e1a76765f55fcdfa15a1 |
|
BLAKE2b-256 | 9c7450ad64103113d6a483fa61169d354877e0b0a2d1ecc4069f77dca9cf22aa |