filefield djanfo code example
Example 1: Django forms I cannot save picture file
def upload_pic(request):
if request.method == 'POST':
form = ImageUploadForm(request.POST, request.FILES)
if form.is_valid():
m = ExampleModel.objects.get(pk=course_id)
m.model_pic = form.cleaned_data['image']
m.save()
return HttpResponse('image upload success')
return HttpResponseForbidden('allowed only via POST')
Example 2: Django forms I cannot save picture file
class ImageUploadForm(forms.Form):
"""Image upload form."""
image = forms.ImageField()