'django image form does not save image
hey i got a issue with saving image. when i use the admin side it works well, but when i add a employee with frontend form it save evrything exept the image.
<form id="form" method="POST" action="{% url 'addForm' %}" enctype="multipart/form-data" >
{% csrf_token %}
{{form | crispy}}
<input type="submit" name="submit" value="submit" >
</form>
def index(request):
employe = Employe.objects.all()
form = EmployeForm
teamFilter = Employe_Filter(request.GET, queryset=employe)
employe = teamFilter.qs
count = employe.count()
context = {
'employe': employe,
'form': form,
'teamFilter': teamFilter,
'count': count
}
return render(request, 'managements/index.html', context)
class EmployeForm(forms.ModelForm):
class Meta:
model = Employe
fields = '__all__'
MEDIA_URL = '/images/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')
name = models.CharField(max_length=200, null=True)
surname = models.CharField(max_length=200, null=True)
work_number = models.BigIntegerField(null=True)
rank = models.CharField(max_length=200, null=True)
team = models.CharField(choices=TEAMS, max_length=200, default='Teams')
workplace = models.CharField(max_length=200, null=True)
email = models.CharField(max_length=200, null=True)
phone = models.CharField(max_length=200, null=True)
image = models.ImageField(null=True, blank=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|