0

我正在尝试从我的数据库中删除一个 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'),
)

作为记录,我不太了解正则表达式,所以如果这里有明显的错误,请多多包涵。

4

1 回答 1

1

url.py 中的错误网址

它应该看起来像这样:

(r'^/minion/deleteJob/(\w+)/$', 'deleteJob'),

或者如果你也有数字:

(r'^/minion/deleteJob/([a-zA-Z0-9\-\s]+)/$', 'deleteJob'),
于 2013-06-17T14:52:34.830 回答