int()的基数为10的文字无效:

时间:2014-04-14 12:15:25

标签: django

在视图中,我收到错误消息:invalid literal for int() with base 10

views.py

author_id = request.POST.get('id_author')
input_author= Engineer.objects.get(id=author_id)

1 个答案:

答案 0 :(得分:2)

POST字典中的项目默认为字符串。您必须使用int方法将它们转换为整数:

author_id = int(request.POST.get('id_author'))
input_author = Engineer.objects.get(id=author_id)