Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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错误:在一个html中显示两个模型时_Python_Django - Fatal编程技术网

Python Django错误:在一个html中显示两个模型时

Python Django错误:在一个html中显示两个模型时,python,django,Python,Django,我想在一个模板html(结果)中显示两个模型(输入;结果): 错误是“ResultView”未定义。如果下面有什么错误,请纠正我。提前谢谢你的建议 结果-视图.py from result.models import Result from inputform.models import Input class ResultView(ListView): context_object_name = 'result_list' template_name = 'result_li

我想在一个模板html(结果)中显示两个模型(输入;结果):

错误是“ResultView”未定义。如果下面有什么错误,请纠正我。提前谢谢你的建议

结果-视图.py

from result.models import Result
from inputform.models import Input

class ResultView(ListView):
    context_object_name = 'result_list'
    template_name = 'result_list.html'
    queryset = Result.objects.all()

    def get_context_data(self, **kwargs):
        context = super(ResultView, self).get_context_data(**kwargs)
        context['input'] = Input.objects.all()
        return context
url

from django.views.generic.list import ListView
from result.views import ResultView

  urlpatterns = patterns('',

    url(r'^result_list/$',ResultView.as_view(),name='dupont'),
    url(r'^input', 'inputform.views.input',name='input'),  
)
结果列表---HTML

 <div class="basicinfo">         <!--Input information-->
    {% for input in input_list %}    ------If here correct?
        <table border="1" cellpadding="1">
        <tr>
          <td align="left">Company</td>
            <td>{{input.company}}</td>
        </tr>
        <tr>
        </table>
   {% endfor %}
 </div>

<div class="result">         <!--Result information-->
    {% for result in Result_list %}               ----If here correct?
        <table border="1" cellpadding="1">
        <tr>
          <td align="left">Totao</td>
            <td>{{result.Total}}</td>
        </tr>
        <tr>
        </table>
   {% endfor %}

{%用于输入列表%}中的输入------这里是否正确?
单位
{{input.company}
{%endfor%}
{结果列表中的结果为%}----这里是否正确?
托托
{{result.Total}
{%endfor%}

将ListView而不是ResultView导入URL.py。

将ListView而不是ResultView导入URL.py。

将ListView而不是ResultView导入URL.py。

将ListView而不是ResultView导入URL.py

  • 您需要在url.py中导入ResultView
  • 您将上下文对象名称命名为结果列表,当您在结果列表.html中引用它时,应坚持使用结果列表,而不是使用结果列表
  • 因为您编写了
    context[input]=…
    ,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:

    {% for item in input %}
        ...
    
  • 您需要在url.py中导入ResultView
  • 您将上下文对象名称命名为结果列表,当您在结果列表.html中引用它时,应坚持使用结果列表,而不是使用结果列表
  • 因为您编写了
    context[input]=…
    ,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:

    {% for item in input %}
        ...
    
  • 您需要在url.py中导入ResultView
  • 您将上下文对象名称命名为结果列表,当您在结果列表.html中引用它时,应坚持使用结果列表,而不是使用结果列表
  • 因为您编写了
    context[input]=…
    ,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:

    {% for item in input %}
        ...
    
  • 您需要在url.py中导入ResultView
  • 您将上下文对象名称命名为结果列表,当您在结果列表.html中引用它时,应坚持使用结果列表,而不是使用结果列表
  • 因为您编写了
    context[input]=…
    ,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:

    {% for item in input %}
        ...
    

  • 您的
    url.py中有一个拼写错误。您尝试使用
    ReultView
    而不是
    ResultView
    。 要访问模板中的数据,必须使用上下文名称。如果将
    Input
    对象添加为
    context['Input']=Input.objects.all()
    ,则需要以以下方式循环:

    <div class="basicinfo">
        {% for input_object in input %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Company</td>
                    <td>{{input_object.company}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {input%}中的input_对象为%
    单位
    {{input_object.company}
    {%endfor%}
    
    您的结果列表名称是结果列表而不是结果列表:

    <div class="result">
        {% for result in result_list %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Totao</td>
                    <td>{{result.Total}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {result_list%}中的结果为%
    托托
    {{result.Total}
    {%endfor%}
    
    您的
    URL.py中有一个拼写错误。您尝试使用
    ReultView
    而不是
    ResultView
    。 要访问模板中的数据,必须使用上下文名称。如果将
    Input
    对象添加为
    context['Input']=Input.objects.all()
    ,则需要以以下方式循环:

    <div class="basicinfo">
        {% for input_object in input %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Company</td>
                    <td>{{input_object.company}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {input%}中的input_对象为%
    单位
    {{input_object.company}
    {%endfor%}
    
    您的结果列表名称是结果列表而不是结果列表:

    <div class="result">
        {% for result in result_list %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Totao</td>
                    <td>{{result.Total}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {result_list%}中的结果为%
    托托
    {{result.Total}
    {%endfor%}
    
    您的
    URL.py中有一个拼写错误。您尝试使用
    ReultView
    而不是
    ResultView
    。 要访问模板中的数据,必须使用上下文名称。如果将
    Input
    对象添加为
    context['Input']=Input.objects.all()
    ,则需要以以下方式循环:

    <div class="basicinfo">
        {% for input_object in input %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Company</td>
                    <td>{{input_object.company}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {input%}中的input_对象为%
    单位
    {{input_object.company}
    {%endfor%}
    
    您的结果列表名称是结果列表而不是结果列表:

    <div class="result">
        {% for result in result_list %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Totao</td>
                    <td>{{result.Total}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {result_list%}中的结果为%
    托托
    {{result.Total}
    {%endfor%}
    
    您的
    URL.py中有一个拼写错误。您尝试使用
    ReultView
    而不是
    ResultView
    。 要访问模板中的数据,必须使用上下文名称。如果将
    Input
    对象添加为
    context['Input']=Input.objects.all()
    ,则需要以以下方式循环:

    <div class="basicinfo">
        {% for input_object in input %}
            <table border="1" cellpadding="1">
                <tr>
                    <td align="left">Company</td>
                    <td>{{input_object.company}}</td>
                </tr>
            </table>
        {% endfor %}
    </div>
    
    
    {input%}中的input_对象为%
    单位
    {{input_object.c