Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.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

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_Ajax - Fatal编程技术网

Python 函数返回未在Django中呈现的多个复选框输入

Python 函数返回未在Django中呈现的多个复选框输入,python,django,ajax,Python,Django,Ajax,我有一个数据库调用来检索myviews.py中的一些记录 def database(request): if request.method=="POST": #connect to the database #retrieve the results res = cur.fetchall() area_input = forms.DefineArea() tables_input = fo

我有一个数据库调用来检索myviews.py中的一些记录

def database(request):
    if request.method=="POST":
        #connect to the database
        #retrieve the results
        res = cur.fetchall()
        area_input = forms.DefineArea()
        tables_input = forms.DefineArea().print_tables(res)
        
        cur.close()
        con.close()
    dictionary = {'area_input': area_input, 'tables_input': tables_input}
    return render(request, "main/tables.html", context=dictionary)
在my forms.py中,我有:

from django import forms

class DefineArea(forms.Form):
    area_name = forms.CharField(max_length=150)

    @staticmethod
    def print_tables(res):
        tables = []
        for row in res:
            tables.append((row[0], row[0]))
        tables_input = forms.MultipleChoiceField(choices=tables, required=False, widget=forms.CheckboxSelectMultiple())
        return tables_input
我知道这是可行的,因为如果我返回表格而不是表格输入,我会看到所有表格都以HTML格式打印。但当我在Postman中测试它时,我看到的是对象对位置的引用:

但是如果我像我提到的那样改变它:

class DefineArea(forms.Form):
    area_name = forms.CharField(max_length=150)

    @staticmethod
    def print_tables(res):
        tables = []
        for row in res:
            tables.append((row[0], row[0]))
        tables_input = forms.MultipleChoiceField(choices=tables, required=False, widget=forms.CheckboxSelectMultiple())
        return tables
tables只是我从数据库中获得的表列表:

我需要做些什么来渲染Django对象吗