我正在尝试从我的数据库中删除Job对象,并且我一直收到错误:
TypeError at /minion/deleteJob/
deleteJob() takes exactly 2 arguments (1 given)
Request Method: GET
Request URL: http://127.0.0.1:8000/minion/deleteJob/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:
deleteJob() takes exactly 2 arguments (1 given)
Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response, line 115
Python Executable: /usr/bin/python
Python Version: 2.7.4
Python Path:
['/home/jgreen/MinionDjangoApp/minion',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-i386-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
Server time: Mon, 17 Jun 2013 09:34:21 -0500
Traceback Switch to copy-and-paste view
/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response
response = callback(request, *callback_args, **callback_kwargs)
...
▶ Local vars
Request information
GET
No GET data
POST
No POST data
FILES
以下是我用来尝试删除作业的代码:
#deletes the selected job from the database
def deleteJob(request, name):
j = Job.objects.get(pk=3)
Job.objects.filter(name=name).delete()
return render_to_response('Minion/detail')
如果有人知道导致这个错误的原因似乎是源于python库,我将非常感激。
编辑:urls.py
from django.conf.urls import patterns, include, url
from django.views.generic import DetailView, ListView
from django.conf.urls.defaults import *
from Minion.models import Job
urlpatterns = patterns('Minion.views',
# URLs for the MinionUI app
url(r'^$', 'home'),
url(r'^index/$', 'detail'),
url(r'^add/$', 'add'),
url(r'^output/$', 'output'),
url(r'^cal/$', 'calendarTest'),
url(r'^addJobData/$', 'addJobData'),
url(r'^deleteJob/$', 'deleteJob'),
)
为了记录,我不太了解正则表达式,所以如果这里有明显的错误,请耐心等待。
答案 0 :(得分:1)
url.py中的错误网址
看起来应该是这样的:
(r'^/minion/deleteJob/(\w+)/$', 'deleteJob'),
或者如果您还有数字:
(r'^/minion/deleteJob/([a-zA-Z0-9\-\s]+)/$', 'deleteJob'),