I amd new to Tornado framework and trying to make a simple form to upload images:
JavaScript
x
6
1
<form method="post" action="/uploads/{{uid}}/" enctype="multipart/form-data" >
2
<input type="file" name="file1" /> <br />
3
Image info: <input type="text" name="alt" /> <br />
4
<input class="button" type="submit" value="Upload" class="button" />
5
</form>
6
I can successfully receive the Posted file using:
JavaScript
1
4
1
if 'file1' in self.request.files:
2
if self.request.files['imgfile'][0]:
3
file1 = self.request.files['imgfile'][0]
4
However I’m unable to receive the alt
input. I tried alt = self.request.alt
but I get this error
JavaScript
1
2
1
AttributeError: 'HTTPServerRequest' object has no attribute 'alt'
2
and when I use alt = self.request.files['alt']
, I get:
JavaScript
1
2
1
KeyError: 'alt'
2
I ran out of ideas so appreciate your help.
UPDATE:
I found that this works:
JavaScript
1
2
1
alt = self.get_argument('alt')
2
But still open for better solutions.
Advertisement
Answer
Try code below
JavaScript
1
2
1
self.get_body_argument("alt", default=None, strip=False)
2