Python django html中未显示表单字段

Python django html中未显示表单字段,python,django,Python,Django,我已经写了一个代码来生成表单,我猜不出为什么这里没有显示字段是我的代码 我想从index.html页面获取一个请求,并使用该请求运行一个查询以在同一页面上显示查询结果 views.py def search123(request): searc=search1() if request.method=="POST": searc=search1(request.POST or None) if searc.is_valid():

我已经写了一个代码来生成表单,我猜不出为什么这里没有显示字段是我的代码

我想从index.html页面获取一个请求,并使用该请求运行一个查询以在同一页面上显示查询结果

views.py
def search123(request):
  searc=search1()
  if request.method=="POST":        
        searc=search1(request.POST or None)
        if searc.is_valid():
            if 'd_box' in request.POST:
                item_map=item.objects.raw('SELECT * FROM `item` WHERE `category_id`=%s', [request.POST['d_box']])
                lis=[]
                for e in (item_map):
                    lis.append(e.id)
                price_map=item_done.objects.filter(item_id__in=lis).order_by('item_id')
                return render_to_response('index.html',{'posts':price_map},RequestContext(request))
  return render_to_response('index.html',{'posts':searc},RequestContext(request))


我认为您必须导入
表单中的
搜索
模型。py
模板中的表单名称也写错了!您编写的
{{searc.as_table}}
必须是
{{search.as_table}}

您是否以forms.py导入搜索模型?是的,否则会显示错误答案如何?您是否优化了searc.asatable
?你现在的错误是什么?我之前没有收到任何错误,它也没有在表单上显示字段。还是空白
index.html

<html>
<head>   
</head>

<body>
<form method='POST' action=''>{% csrf_token %}
<h4> SEARCH </h4>
{{searc.as_table}}
<input type='submit' name="button7" value="button7">
</form>


{% regroup posts by item_id as post_list %}

<table border="4" style="width:1050px;border-collapse: collapse" >
    <thead>
            <tr>
            <th>Item Codes</th>
            <th>Name</th>
            <th>MRP</th>
            <th>Site price</th>
            <th>Website</th>
            </tr>

          </thead>        
     <tbody>           


{% for country in post_list %}

    <tr>
    <td>{{ country.grouper }}</td>
    <td>
        {% for item in country.list %}
        <div style="margin: 5px 5px">{{item.name}}</div>
        {% endfor %}    
    </td>


       <td>
        {% for item in country.list %}
        <div style="margin: 5px 5px">{{item.mrp}}</div>
        {% endfor %}    
    </td>

    <td>
        {% for item in country.list %}
        <div style="margin: 5px 5px">{{item.site_price}}</div>
        {% endfor %}    
    </td>

    <td>
        {% for item in country.list %}
        <div style="margin: 5px 5px">{{item.crawl_id}}</div>
        {% endfor %}    
    </td>


    </tr>
{% endfor %}

     </tbody>
</table>
</html>
forms.py
class search1(forms.ModelForm):
    class Meta:
        model=search
        exclude=[]