Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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
试图在my base.html中包含django表单,但不在其他模板中呈现?_Django_Django Forms_Django Haystack - Fatal编程技术网

试图在my base.html中包含django表单,但不在其他模板中呈现?

试图在my base.html中包含django表单,但不在其他模板中呈现?,django,django-forms,django-haystack,Django,Django Forms,Django Haystack,我正在使用django haystack进行搜索,并希望将表单包含在base.html文件中,以便它显示在我的所有模板中。当我加载到默认url时,它将显示在上,但我无法获取表单标记{{form.as_table}},以便在加载结果模板时显示。html表单仍然存在,但表单标签不存在 这些都包含在base.html中 <form method="get" action="."> <table> ##{{ form.as_table }} ## this

我正在使用django haystack进行搜索,并希望将表单包含在base.html文件中,以便它显示在我的所有模板中。当我加载到默认url时,它将显示在上,但我无法获取表单标记{{form.as_table}},以便在加载结果模板时显示。html表单仍然存在,但表单标签不存在

这些都包含在base.html中

<form method="get" action=".">
    <table>
        ##{{ form.as_table }} ## this doesn't show up when loading the results template
        <tr>
            <td>&nbsp;</td>
            <td>
                <input type="submit" value="Search" class="btn btn-primary">
            </td>
        </tr>
    </table>
</form>

##{{form.as_table}}##这在加载结果模板时不会显示

可能只有主视图在您的上下文中定义了
表单所有视图必须定义它:

context['form'] = MyFormClass()
你应该使用一个。看看这个,它对我有用