在urls.py中:
(r'^airAgency/(?P<key>[a-zA-Z0-9]+)/edittour/(?P<tour_id>\d+)/$','airAgency.views.edittour'),在views.py中:
tour.save()
ang=Agent.objects.get(pk=key)
return HttpResponseRedirect('airAgency/%s/edittour/%i/edittour.html' % (agn.WebSite,tour.pk))注意:教程是一个表单,保存表单后使用教程pk传递到edittour.html,但在重定向到edittour.html时会出现以下错误:
ValueError at /airAgency/mastane/addtour/
invalid literal for int() with base 10: 'mastane'
Request Method: POST
Request URL: 127.0.0.1:8080/airAgency/mastane/addtour
Django Version: 1.3
Exception Type: ValueError
Exception Value: invalid literal for int() with base 10: 'mastane'
Exception Location: C:\Python26\lib\site-packages\django\db\models\fields_init_.py in get_prep_value, line 479
Python Executable: C:\Python26\python.exe 发布于 2011-10-25 20:58:25
%i格式说明符无法将tour.pk的值转换为整数。
它需要是包含整数的字符串(带符号或不带符号,忽略前导零)、数值类型(如float )或具有__int__方法的类。
发布于 2011-10-25 21:43:15
正如agf所说,你可以通过简单的替换这一行来解决你的问题:
return HttpResponseRedirect('airAgency/%s/edittour/%s/edittour.html' % (agn.WebSite,str(tour.pk)))假设tour.pk大于(或等于) 0...
发布于 2011-10-25 23:54:42
你有一个打字错误:
ang=Agent.objects.get(pk=key)
...% (agn.WebSite正如@agf在评论中指出的,你的tour.pk的值似乎是'mastane‘而不是一个整数。
https://stackoverflow.com/questions/7889532
复制相似问题