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.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3c564b661c298beb5cd0570ee4b7373bad0225a1af9aa9b9ef793e408b59e52 |
|
MD5 | a10372be2a5e4865be29edd1e6cde35b |
|
BLAKE2b-256 | 6893be4559261d24c8f63b87c531540db5fd4e2d22ba533bc6d4992a87761d87 |
Close
Hashes for django_request_mapping-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6188d8493ee2e6879565f91da6a7c643e75769056cbc449d5a765b1fca845fca |
|
MD5 | 42d9d047e476b9344365a065c105053e |
|
BLAKE2b-256 | 7766f48ed601a60d3db70c13451c54234fff0530e5e80eac2f76e86d6b9b8f46 |