最多" pythonic"基于方法处理同一网址上的视图路由的方法?我不喜欢这个解决方案
if(request.method == 'GET'):
.......
有更好的方法吗?
答案 0 :(得分:2)
Django View是最pythonic的代码。
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'),
]