我有以下形式:清潔值
class SourceForm(forms.ModelForm):
class Meta:
model = Source
widgets = {
'category_re': forms.TextInput(),
'thumb_re': forms.TextInput(),
'movie_re': forms.TextInput()
}
def clean_url(self):
data = self.cleaned_data['url']
return helpers.url_fix(data)
和以下觀點:
def source_form(request, id):
source = get_object_or_404(Source, pk=id)
form = SourceForm(request.POST or None, instance=source)
if form.is_valid():
form.save()
return render_to_response('source/form.html', {'form': form, 'source': source},
context_instance=RequestContext(request))
和我有問題。表格中未顯示url
字段的清除值。我只看到舊的,未修改的值,但後來我嘗試在模板中添加{{ form.cleaned_data }}
- 它顯示正確的值。爲什麼發生這種事?我該如何解決它?
TIA!
試試:'如果self.is_valid:'數據= self.cleaned_data [ 'URL']'clean_url' – karthikr
THX的答案!它沒有效果。 – dizpers