What is the most "pythonic" way to handle view routing on same url based on method? i don't like the solution
if(request.method == 'GET'):
.......
is there a better way?
Django View is the most pythonic code.
from django.http import HttpResponse
from rest_framework.views import APIView
class MyView(APIView):
def get(self, request):
# <view logic>
return HttpResponse('result')
def post(self, request):
# <view logic x2>
return HttpResponse('message_post_template')
urls.py
from django.conf.urls import url
from myapp.views import MyView
urlpatterns = [
url(r'^about/$', MyView.as_view(), name='view'),
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With