Python Django错误:在一个html中显示两个模型时
我想在一个模板html(结果)中显示两个模型(输入;结果): 错误是“ResultView”未定义。如果下面有什么错误,请纠正我。提前谢谢你的建议 结果-视图.pyPython 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
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
context[input]=…
,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:
{% for item in input %}
...
context[input]=…
,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:
{% for item in input %}
...
context[input]=…
,这意味着当您在模板中访问它时,输入列表的名称是input,而不是input\u list,因此,您应该使用:
{% for item in input %}
...
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