41👍
✅
You should add the enctype=multipart/form-data
attribute to the <form>
tag:
<form method='POST' action='{{ action_url }}' enctype='multipart/form-data'>
2👍
except for adding enctype=multipart/form-data
, another possible reason that your image is not saving in modelform
can be adding request.FILES
in your POST
condition:
if request.method == 'POST':
form = forms.ProjectCreateForm(request.POST, instance=project)
should be:
if request.method == 'POST':
form = forms.ProjectCreateForm(request.POST, request.FILES, instance=project)
- What does it mean for an object to be unscriptable?
- Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
- 'CheckoutView' object has no attribute 'object'
- Django raw_id_fields widget not showing search icon
- 'Questions ' object is not iterable Django
- How to make a field editable on create and read-only on update in Django REST framework
- Calling a function in Django after saving a model
- Whole model as read-only
- Django custom user model in admin, relation "auth_user" does not exist
Source:stackexchange.com