Python 在Django中构建页面
我刚到django。我想知道,我应该如何在django中构建许多视图? 实际上我有这样的代码: views.py:Python 在Django中构建页面,python,django,Python,Django,我刚到django。我想知道,我应该如何在django中构建许多视图? 实际上我有这样的代码: views.py: # BACKEND from django.shortcuts import render from django.http import HttpResponse, HttpRequest # Create your views here. CSRF_COOKIE_SECURE = True postData: dict = {} # INDEX - MAIN PAGE
# BACKEND
from django.shortcuts import render
from django.http import HttpResponse, HttpRequest
# Create your views here.
CSRF_COOKIE_SECURE = True
postData: dict = {}
# INDEX - MAIN PAGE
def indexPage(request):
print(postData)
return render(request, "index.html")
# REGISTER PAGE
def registerPage(request):
postData = request.POST
但我认为代码可以用类包装,如下所示
class ServiceMap(object):
# INDEX - MAIN PAGE
def indexPage(self):
return render("index.html")
def registerPage(self):
return render("registerPage.html")
def loginPage(self):
return render("loginPage.html")
# ETC
class RequestHandler(object):
postData = {}
def captureRequest(self,request):
postData = request.POST
def getPostData(self):
if self.__postData is not None:
return postData
else:
postData = None
return postData
我不确定这是一种正确的方法,因为我无法处理来自POST请求的数据。我想知道,构建视图最优雅的方式是什么。听起来你应该学习一些Django教程。关于基于类的视图与标准视图的官方说法。