Reputation: 393
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?
Upvotes: 3
Views: 4435
Reputation: 515
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'),
]
Upvotes: 6