Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Delete()视图和模板代码_Python_Django - Fatal编程技术网

Python Delete()视图和模板代码

Python Delete()视图和模板代码,python,django,Python,Django,模板: <form method="POST" action="/customer/delete/"> <div style="float: right; margin: 0px; padding: 05px; "> Name:<select name="customer"> {% for customer in customer %} <option value="{{ customer.name|escape }}" &

模板:

<form method="POST" action="/customer/delete/">
<div style="float: right; 
             margin: 0px; padding: 05px; ">
Name:<select  name="customer">
{% for customer in customer %}
<option value="{{ customer.name|escape }}" ></option><br />
{% endfor %}
</select>
<input type=submit value="delete">  
</div>
</form> 
url.py

(r'^customer/delete/', 'quote.excel.views.delete'),
这不起作用,请更正代码

Customer.objects.get(name = request.POST['name']).delete()
顺便问一下,您确定模板中的
操作
变量确实是
'delete'
?如果不是,则调用的url(以及方法)将不同

<form method="POST" action="/customer/{{ action }}/">

顺便问一下,您确定模板中的
操作
变量确实是
'delete'
?如果不是,则调用的url(以及方法)将不同

<form method="POST" action="/customer/{{ action }}/">

您的URLConf没有捕获任何数据以传递给变量
name
。您需要将其作为URL的一部分进行捕获,或者将其保留在已发布的参数中进行捕获

作为URL的一部分:

(r'^customer/(?P<name>[a-z]*)/delete/', 'quote.excel.views.delete')

def delete(request, name):
    if request.method == "POST": 
        # GET requests should NEVER delete anything, 
        # or the google bot will wreck your data.
        Customer.objects.get(name=name).delete()

您的URLConf没有捕获任何要传递给变量
name
的数据。您需要将其作为URL的一部分进行捕获,或者将其保留在已发布的参数中进行捕获

作为URL的一部分:

(r'^customer/(?P<name>[a-z]*)/delete/', 'quote.excel.views.delete')

def delete(request, name):
    if request.method == "POST": 
        # GET requests should NEVER delete anything, 
        # or the google bot will wreck your data.
        Customer.objects.get(name=name).delete()

@“我的模板”下拉框中的amarghosh没有从数据库中获取数据。错误在哪里?@daffodil它取决于原始视图-您已为“删除”按钮的单击处理程序发布了视图。@我的模板下拉框中的amarghosh没有从数据库中获取数据。错误在哪里?@daffodil它取决于原始视图-您已为数据库发布了视图“删除”按钮的“单击”处理程序。我对该url有问题,您已在上面的“页面未找到”(404)请求方法中说明:POST Request url:/)/delete/。这是错误。缺少括号。现在已经修复。我自己更正了它,但它仍然是一样的。Thnx为您提供帮助。请看,这您将知道mistk delete视图在哪里,它说明此错误delete()正好使用了2个参数(1个给定)我对该url有问题,您在上面的页面未找到该url(404)请求方法:POST请求URL:///delete/。这是错误。缺少括号。现在已修复。我自己更正了它,但它仍然是一样的。Thnx为您提供帮助。请看,您将知道mistk delete视图的位置,它声明此错误delete()正好包含2个参数(给定1个)