2013-02-22 27 views
0

我在一個頁面上有多個表單,我的視圖通過檢查提交的值來處理這些表單。這似乎工作一切正常,但我的形式是在下面的錯誤。在Django沒有屬性'方法'

'QueryDict' object has no attribute 'method' 

VIEW

def all(request): 
if request.method == 'POST': 
    if 'all' in request.POST['submit']: 
     all(request.POST) 
    elif 'addtype' in request.POST['submit']: 
     addtype(request.POST) 
    elif 'addnewpm' in request.POST['submit']: 
     addnewpm(request.POST) 
    elif 'addnewspec' in request.POST['submit']: 
     addnewspec(request.POST) 
    elif 'update' in request.POST['submit']: 
     update(request.POST) 
    elif 'addnewrecord' in request.POST['submit']: 
     addnewrecord(request.POST) 

基本上我只是路過後值根據所按下的提交按鈕上單獨的功能。除了第一個「全部」之外,它們都工作正常。 '全部'提交按鈕提交大量數據,並且我可以在回溯中看到所有這些數據。

也許它與我的HTML代碼有關。

<table class="gridtable"> 
<tr> 
<td class="topheader-left" colspan="10">  
<form action="" method="post"> 
<button type="submit" value="all" name="submit" style="border:0px;"> 
<img src="{% get_static_prefix %}images/update.png" style="width:27px;height:27px;"> 
</button> 
</td> 
</tr> 

在此之下,我只是有大量的表格單元格的字段和一個/表格在最後。

來自我的網頁上的一個表單的代碼正常工作。

<table width="100%"> 
<tr> 
<form method="post" action=""> 
<td> 
<input id="newtype" type="text" name='newtype' size="40" value="Service Type"> 
</td> 
<td> 
<button name="submit" type="submit" value="addtype" style="border:0px;"> 
<img src="{% get_static_prefix %}images/Add-icon.png" width="20" height="20" border="0"> 
</button> 
</td> 
</form> 

此表格似乎工作正常。我不明白我在做什麼不同。

乾杯傢伙。

+0

看起來像是在第二次調用時使用'request.POST'作爲參數遞歸調用'all()'函數。 – 2013-02-22 01:09:02

回答

1

看起來像一個簡單的函數名稱衝突。您的查看方法名稱是all,並且您一次又一次地撥打all(request),並再次:)如果值爲submit == all

使用in來尋找在request.POST中提交的值。爲什麼不只是設置一次值並且以這種方式比較呢?

submit = request.POST['submit'] 

if submit == 'all': 
    # call method 
elif submit == 'addtype': 
    # etc 
+0

嘿,夥計們,哇,不敢相信我沒有選擇那個,一定是在一個完全不同的思維浪潮中。看起來像已修復它。非常感謝。 – dlyxzen 2013-02-22 01:27:21

+0

不用擔心。我喜歡當我編輯錯誤的文件,並想知道爲什麼我的變化沒有顯示:) – Brandon 2013-02-22 01:28:20

+0

哈哈,是的,那裏,做到了,因爲我期望每個人都有:) - 乾杯 – dlyxzen 2013-02-22 02:34:13

相關問題