我认为您可以在不向URL添加一堆逻辑的情况下使用不同的函数来完成此操作(这从来都不是个好主意),但是您可以在函数中检查request方法:
def myview(request):
if request.method == 'GET':
# Code for GET requests
elif request.method == 'POST':
# Code for POST requests
您还可以切换到基于类的视图。然后,您只需要为每个HTTP方法定义一个方法:
class CreateMyModelView(CreateView):
def get(self, request, *args, **kwargs):
# Code for GET requests
def post(self, request, *args, **kwargs):
# Code for POST requests
如果您决定采用基于课程的路线,那么另一个不错的资源是http://ccbv.co.uk/。