0

我在一页上有多个表单,我的视图是通过检查提交的值来处理这些表单。这似乎一切正常,但是在我的表单中出现以下错误。

'QueryDict' object has no attribute 'method'

看法

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>

在此之下,我只有大量带有字段的表格单元格,最后是 /form。

我页面上其中一种表单的代码运行良好。

<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>

这种形式似乎工作正常。我不明白我在做什么不同。

干杯,伙计们。

4

1 回答 1

1

似乎是一个简单的函数名冲突。您的视图方法名称是allall(request)如果submit == all.

使用in在 request.POST 中查找 submit 的值似乎很奇怪。为什么不只设置一次值并以这种方式进行比较呢?

submit = request.POST['submit']

if submit == 'all':
    # call method
elif submit == 'addtype':
   # etc
于 2013-02-22T01:04:41.290 回答