有一个由普通HTML表单元素组成的表单和一起上传文件。当我使用它时,文件上传工作,但普通形式不工作 我可以设置吗? 处理功能如下:
class OSCForm(blobstore_handlers.BlobstoreUploadHandler):
def get(self):
upload_url = blobstore.create_upload_url('/oscform.html')
template_values = {
'action_url': upload_url
}
template = JINJA_ENVIRONMENT.get_template('oscform.html')
self.response.write(template.render(template_values))
def post(self):
osc=OSC()
osc.f_title=self.request.get('f_title')
osc.f_id=self.request.get('f_id')
osc.f_os=self.request.get('f_os')
osc.f_bnf=self.request.get('f_bnf')
osc.f_contractor=self.request.get('f_contractor')
osc.f_loc=self.request.get('f_loc')
osc.f_adr=self.request.get('f_adr')
osc.f_exp1=self.request.get('f_exp1')
osc.f_exp2=self.request.get('f_exp2')
osc.f_ipa=self.request.get('f_ipa')
osc.f_type=self.request.get('f_type')
osc.f_date=self.request.get('f_date')
osc.f_level=self.request.get('f_level')
upload = self.get_uploads()[0]
blob_key=upload.key()
osc.f_annex=blob_key
savedosc=osc.put()
顺便说一下; HTML表单在下面
<form method="post" enctype="multipart/form-data" name="CONTROLRECORDS" id="CONTROLRECORDS" action="{{action_url}}">
<dl>
<dt>
<label for="f_title">Contract Title</label>
</dt>
<dd>
<input type="text" id="f_title" class="required" name="f_title" style="background-image: url(http://www.reformedapp.com/themes/reformed-form-start/images/ui-bg_inset-hard_100_fcfdfd_1x100.png); background-position: 50% 100%; background-repeat: repeat no-repeat;" />
</dd>
</dl>
<dl>
<dt>
<label for="f_id">Contract ID</label>
</dt>
<dd>
<input type="text" id="f_id" class="required" name="f_id" />
</dd>
</dl>
<dl>
<dt>
<label for="f_os">Operation Structure</label>
</dt>
<dd>
<select size="1" name="f_os" id="f_os">
<option value="MoEU">MoEU</option>
<option value="MoLSS">MoLSS</option>
<option value="MoSIT">MoSIT</option>
<option value="MoTMC">MoTMC</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_bnf">Beneficiary</label>
</dt>
<dd>
<input type="text" id="f_bnf" name="f_bnf" />
</dd>
</dl>
<dl>
<dt>
<label for="f_contractor">Contractor</label>
</dt>
<dd>
<input type="text" id="f_contractor" name="f_contractor" />
</dd>
</dl>
<dl>
<dt>
<label for="f_loc">Related Location of Project</label>
</dt>
<dd>
<select size="1" name="f_loc" id="f_loc">
<option value="ANKARA">ANKARA</option>
<option value="ISTANBUL">ISTANBUL</option>
<option value="ADANA">ADANA</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_adr">Adress(District or Village Name)</label>
</dt>
<dd>
<input type="text" id="f_adr" name="f_adr" value="CENTER" />
</dd>
</dl>
<dl>
<dt>
<label for="f_exp">Expert 1</label>
</dt>
<dd>
<select size="1" name="f_exp" id="f_exp">
<option value="">SUAT ATAN</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_exp2">Expert 2</label>
</dt>
<dd>
<select size="1" name="f_exp2" id="f_exp2">
<option value="">SUAT ATAN</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_ipa">IPA component</label>
</dt>
<dd>
<select size="1" name="f_ipa" id="f_ipa">
<option value="IPA1">IPA1</option>
<option value="IPA2">IPA2</option>
<option value="IPA3">IPA3</option>
<option value="IPA4">IPA4</option>
<option value="IPARD">IPARD</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_type">Contract Type</label>
</dt>
<dd>
<select size="1" name="f_type" id="f_type">
<option value="WORKS">WORKS</option>
<option value="SUPPLY">SUPPLY</option>
<option value="GRANT">GRANT</option>
<option value="SERVICE">SERVICE</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_date">OSC Date</label>
</dt>
<dd>
<input type="text" id="f_date" class="date" name="f_date" />
</dd>
</dl>
<dl>
<dt>
<label for="f_level">Control Level</label>
</dt>
<dd>
<select size="1" name="f_level" id="f_level">
<option value="DESKREVIEW">DESKREVIEW</option>
<option value="DESKREVIEW+OSC">DESKREVIEW+OSC</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="f_obs">Observations</label>
</dt>
<dd>
<textarea id="f_obs" name="f_obs" rows="5" cols="50"></textarea>
<br>
Upload File: <input type="file" name="file"><br>
</dd>
</dl>
<div id="submit_buttons">
<button type="submit">
Submit
</button>
</div>
</form>