我想展示2款(輸入;結果)在一個HTML模板(結果):Django的錯誤:顯示一個HTML兩種模式時
的錯誤是「ResultView」沒有定義。如果下面有任何錯誤,請糾正我。預先感謝您的建議。
結果 - Views.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
網址
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'),
)
result_list --- 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 %}
發現在'網址拼寫錯誤(R'^ result_list/$',ReultView.as_view(),name ='dupont')'這是'結果'而不是'Reult'。另外,你是否在你的urls.py中導入了ResultView? – Cheng
您是否將ListView導入到您的views.py中? – pythad
是的,我已經導入了ListView。 –