0
我正在嘗試在窗體上進行自定義驗證。但是,clean_
方法不起作用(無論我嘗試什麼)。這是我目前有 -驗證ModelForm
from django.forms import ModelForm
from django import forms
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
avatar = models.ImageField(upload_to='images/%Y/%m/%d', blank=True)
class ProfilePictureForm(ModelForm):
class Meta:
model = UserProfile
fields = ('avatar',)
def clean_avatar(self):
try:
raise # this is just to see if the clean_ is working
except:
raise
而且在views
-
def getting_started_pic(request):
if request.method == 'POST':
profile.avatar = request.FILES['avatar']
profile.save()
return render_to_response (...)
那我爲了得到clean_avatar
法「工作」失蹤? (目前,它好像不在那裏)。謝謝。