I need to save the file through the form, do this:

models.py class Post(models.Model): title = models.CharField(max_length=255) image = ImageField(upload_to='images') forms.py class PostForm(forms.ModelForm): class Meta: model = Post views.py class PostCreateView(CreateView): form_class = PostForm template_name = 'create.html' success_url = '/' 

For example, if I selected a file and did not fill in the title, the page reloads, the title says that the field is mandatory, and the selected file is not displayed, I fill the title and do not select the file again, reloads the page and says that the file is not selected, but if re-select the file, it will be saved ...

I'm wondering, is CreateView working incorrectly with files, or am I doing something wrong?

    1 answer 1

    That's right, file fields in browsers do not save the downloaded file for security reasons. If you want to save, use a special widget like https://github.com/un1t/django-file-resubmit