moadeep
moadeep

Reputation: 4108

django views.upload() got an unexpected keyword argument 'item_id'

To my eye my setup looks identical to the django tutorial on urls for my to do app

model.py

class Item(models.Model):
    author = models.ForeignKey(User)
    tag = models.CharField('Tag', max_length=10, default='')
    name = models.CharField('Brief summary of job', max_length=200)
    created = models.DateTimeField('Created', auto_now=True,auto_now_add=True)
    description = models.TextField('Description of job')

urls.py

urlpatterns = patterns('nc_jobs.views',
 url(r'^(?P<item_id>\d+)/upload/$', 'upload', name='upload'),
              )

views.py

# Upload Document. Attach to item
def upload(request, id):
    pass

However when I go to localhost:8000/nc_jobs/1/upload I get the error upload() got an unexpected keyword argument 'item_id'. I can't fathom what is wrong

Upvotes: 0

Views: 94

Answers (1)

aumo
aumo

Reputation: 5574

You need to call your view argument item_id:

def upload(request, item_id):
    pass

That way, it matches the named group in your URLConf ((?P<item_id>\d+)).

Upvotes: 2

Related Questions