Django:index-error at/customerList/tuple索引超出范围

Django:index-error at/customerList/tuple索引超出范围,django,django-forms,django-templates,django-views,Django,Django Forms,Django Templates,Django Views,有人能帮我吗。我不理解这个错误 索引器at/客户列表/ 元组索引超出范围 它来自这个密码 self.Customer=get\u object\u或_404(Customer,name\u iexact=self.args[0]) 我希望能够从customerForm(F_NAME,L_NAME)和buildingForm(B_USE,B_TYPE)两个表单中查看一些字段。非常感谢您的帮助。谢谢你 Traceback: File "c:\Python27\lib\site-packages\dj

有人能帮我吗。我不理解这个错误

索引器at/客户列表/ 元组索引超出范围

它来自这个密码

self.Customer=get\u object\u或_404(Customer,name\u iexact=self.args[0])

我希望能够从customerForm(F_NAME,L_NAME)和buildingForm(B_USE,B_TYPE)两个表单中查看一些字段。非常感谢您的帮助。谢谢你

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',)
url.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 }}&nbsp;{{ 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...
…部分代码。。。
{customer_list%}中的客户为%
{{customer.id}
…一些代码。。。

您正试图调用从URL conf传递的位置参数(
self.args[0]
),但尚未向实际URL添加任何位置参数。如果你看一下,你会注意到:

四,。一旦其中一个[url]正则表达式匹配,Django就会导入并调用给定的视图,该视图是一个简单的Python函数。视图将作为第一个参数传递HttpRequest,并将正则表达式中捕获的任何值作为剩余参数传递

您没有向视图传递任何参数(位置参数或命名参数),因此
self.args
self.kwargs
中没有任何参数。您需要将URL更改为以下内容:

url(r'^customerList/(\w+)/',customerListView.as_view(), name= "customerList_view"),
或理想情况下,利用以下各项:

url(r'^customerList/(?P\w+/),customerListView.as\u view(),name=“customerList\u view”),

因此,您可以使用
self.kwargs.get(“name”,无)

thks@Timmy O'Mahony:)…更改了它并阅读了指向:)的参考thks,但是为什么我会得到这个错误404错误,说页面未找到?因为
self.kwargs…
中由
get\u object\u或\u 404
使用的字符串与该名称的用户不匹配。通过手动执行查询,检查数据库中是否存在具有该名称的用户。类似于
Customer.objects.filter(name\uu iexact=“bill”)
url(r'^customerList/(?P<name>\w+)/',customerListView.as_view(), name= "customerList_view"),