我想在窗体中将imagefield设置为可选。为此,我给了blank = True null = True但它不起作用。堆栈溢出中有一些问题与我的问题有关,我尝试了所有答案但没有工作了吗?
models.py
class Profile(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
image = models.ImageField(default='null',upload_to='pics',blank=True)
view.py
def register(request):
if request.method == "POST":
form = Register(request.POST,request.FILES)
if form.is_valid():
email = form.cleaned_data['Email']
User_name=form.cleaned_data['Username']
Password=form.cleaned_data['Password']
firstname=form.cleaned_data['Firstname']
lastname=form.cleaned_data['Lastname']
user=User.objects.create_user(username=User_name,
password=Password,email=email,first_name=firstname,
last_name=lastname)
insert = Profile(image = request.FILES('picture', None),user=user)
return redirect('/')
forms.py
class Register(forms.Form):
picture = forms.ImageField() #i am posting only imagefield code