0

尝试加载我的类别时出现以下错误。发布的值为'1'并且存在于数据库中,

TypeError at /events/add/

int() argument must be a string or a number, not 'Category'

Request Method:     POST
Request URL:    http://127.0.0.1:8000/events/new/
Django Version:     1.4
Exception Type:     TypeError
Exception Value:    

int() argument must be a string or a number, not 'Category'

Exception Location:     /Library/Python/2.7/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 537
Python Executable:  /Users/user/Documents/workspace/RoseBud/django-env/bin/python

视图.py

 category = Category.objects.get(pk=form.cleaned_data['category'])
4

1 回答 1

1

听起来返回的对象form.cleaned_data['category']是类别对象,而不是数字。

如果是这种情况,那就做category = form.cleaned_data['category']

打印它以确保。

于 2013-02-01T23:32:29.150 回答