我有一個顯示窗體並保存相同窗體的視圖。首次顯示視圖時,我沒有任何錯誤。然而,保存(發佈)到視圖我收到以下錯誤時:在/ TEST6 /設置/ int()函數的參數Django int()參數必須是字符串或數字
類型錯誤必須是一個字符串或數字,而不是「的QueryDict」
查看
@login_required
def keyword_settings(request, keyword):
keyword = Keyword.objects.get(keyword=keyword, status="Active")
# If we had a POST then get the request post values.
if request.method == 'POST':
# Populate the form with the instance.
form = KeywordFrom(request.POST, instance=keyword)
# Check we have valid data before saving trying to save.
if form.is_valid():
form.save()
form = KeywordFrom(instance=keyword, user=request.user)
context = {'form': form}
return render_to_response('sms/keyword_settings.html', context, context_instance=RequestContext(request))
表
class KeywordFrom(forms.ModelForm):
def __init__(self, user=None, *args, **kwargs):
"""
Init method.
"""
super(KeywordFrom, self).__init__(*args, **kwargs)
if user is not None:
this_originator_name = Originator.objects.for_user(user)
self.fields['sender_name'] = forms.ModelChoiceField(queryset=this_originator_name)
class Meta:
model = Keyword
我知道問題出在SENDER_NAME,但我都試過,沒有解決不同的事情。
爲什麼不合理?你能解釋一下嗎?感謝 – GrantU