Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中构建页面_Python_Django - Fatal编程技术网

Python 在Django中构建页面

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

我刚到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
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教程。关于基于类的视图与标准视图的官方说法。