python - ImageField doesnt work -
python - ImageField doesnt work -
when seek upload file gives me template error, required fill in. code: models:
class ahoja(models.model): image = models.imagefield(upload_to='smayat')
forms:
class ahojaform(modelform): class meta: model = ahoja exclude = ()
view:
def testview(request): if request.method == 'post': # pokud form byl odeslan form = ahojaform(request.post, request.files) # formular s daty if form.is_valid(): form.save() #vytvoří událost homecoming httpresponseredirect('/hlavni_stranka/kalendar/') else: form = ahojaform() # prázdný formulář homecoming render(request, 'hlavni_stranka/test.html', {'form': form,})
the first thing check enctype
attribute in template. docs:
note request.files
contain info if request method post
, <form>
posted request has attribute enctype="multipart/form-data"
. otherwise, request.files
empty.
python django python-3.x django-1.7
Comments
Post a Comment