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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for django_request_mapping-0.0.8.dev0-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2af973ce62fb05d287995a80ecfacbc1357470aa15780bc3afc61f2d14e199 |
|
MD5 | 58e9ef7e89692ac662e9cd514cbb79c8 |
|
BLAKE2b-256 | 5fe69ae0ae04f797fa249b48aae99ea9c72d631dc99af4854c80c107d86e768b |