【发布时间】:2013-04-10 08:47:12
【问题描述】:
谁能帮我解决这个问题。我不明白这个错误
/customerList/ 处的索引错误 元组索引超出范围
它来自这段代码
self.Customer = get_object_or_404(customer, name__iexact=self.args[0])
我希望能够从 customerForm (F_NAME, L_NAME) 和 buildingForm (B_USE, B_TYPE) 这两个表单中执行 ListView 一些字段。任何帮助都非常非常非常感谢。谢谢你。
Traceback:
File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "c:\Python27\lib\site-packages\django\views\generic\base.py" in view
48. return self.dispatch(request, *args, **kwargs)
File "c:\Python27\lib\site-packages\django\views\generic\base.py" in dispatch
69. return handler(request, *args, **kwargs)
File "c:\Python27\lib\site-packages\django\views\generic\list.py" in get
114. self.object_list = self.get_queryset()
File "f:\iqgit\amon\amonsolution\solution\views.py" in get_queryset
59. self.Customer = get_object_or_404(customer, name__iexact=self.args[0])
Exception Type: IndexError at /customerList/
Exception Value: tuple index out of range
views.py
class customerListView(ListView):
template_name = "customerList.html",
model = customer
context_object_name = "customer_list"
def get_queryset(self):
self.Customer = get_object_or_404(customer, name__iexact=self.args[0])
return building.objects.filter(Customer=self.Customer)
def get_context_data(self, **kwargs):
context = super(customerListView, self).get_context_data(**kwargs)
context['building_list'] = building.objects.all()
return context
forms.py
class customerForm(forms.ModelForm):
F_NAME = forms.CharField(widget=forms.TextInput()
L_NAME = forms.CharField(widget=forms.TextInput()
EMAIL = forms.CharField(widget=forms.TextInput()
ADD = forms.CharField(widget=forms.TextInput()
class Meta:
model = customer
class buildingForm(forms.ModelForm):
CUSTOMER = forms.CharField(widget=forms.TextInput()
B_FLOORSPACE = forms.CharField(widget=forms.TextInput()
B_YEAR = forms.CharField(widget=forms.TextInput()
B_USE = forms.ChoiceField(widget=forms.RadioSelect(), choices=c.Use)
B_TYPE = forms.ChoiceField(widget=forms.RadioSelect(), choices=c.Type)
class Meta:
model = building
exclude = ('CUSTOMER',)
urls.py
url(r'^customerList/',customerListView.as_view(), name= "customerList_view"),
customerList.html
...some of code...
{% for customer in customer_list %}
<tr class = {% cycle "row_even" "row_odd" %}>
<td>{{ customer.id }}</td>
<td class ="name"> <a href=" {% url customer_view customer.id %}">{{ customer.F_NAME }} {{ customer.L_NAME }}</a></td>
<td class ="b_use"> <a href=" {% url customer_view customer.id %}">{{ building.B_USE }}{{ building.B_TYPE }}</a></td>
...some of code...
【问题讨论】:
标签: django django-forms django-templates django-views