I am trying to create a form which contains some standard inputs as well as a file input using flask and flask-WTForms. The base of my app is based off of this boilerplate: https://github.com/lingthio/Flask-User-starter-app.
I have a form declared as such:
class DataAnalysisForm(Form):
species = SelectField('species', choices=[
('ecoli', 'Escherichia Coli'),
('yeast', 'Saccharomyces Cerevisiae')
], validators=[validators.Required()])
fileDataType = RadioField('fileType', choices=[
('csv', 'Exponential fold changes (.csv)'),
('fasta', 'Raw RNA-seq data (.fasta/.fastq) (does not work yet!)')
], validators=[validators.Required()], default='csv')
def is_data_file(message="only csv or fasta files", extensions=None):
if (not extensions):
extensions = ['csv', 'fasta', 'fastq']
def _is_data_file(form, field):
if (not field.data or field.data.split('.')[-1] not in extensions):
raise validators.ValidationError(message)
return _is_data_file
seqFile = FileField('seq file', validators=[validators.Required('seq file required'), is_data_file()])
and an html template declared as such:
{% from "common/form_macros.html" import render_field, render_radio_field, render_submit_field %}
<form action="/data_analysis" method="POST" class="form analysis-form" role="form" enctype="multipart/form-data">
{{ form.hidden_tag() }}
<div class="form-group">
<label for="speciesSelect" class="step-label">Step 1: Select the species of your samples</label>
{{ render_field(form.species, label_visible=False) }}
</div>
<div class="form-group fileType">
<label for="expressionData" class="step-label">Step 2: Upload the gene expression data</label>
{{ render_radio_field(form.fileDataType) }}
</div>
<div class="form-group">
{{ render_field(form.seqFile) }}
<small id="fileHelp" class="form-text text-muted form-item-shift">Exponential fold changes are preferred in csv format. More information about input data format is here.</small>
</div>
<button type="submit" class="btn btn-primary job-submit-btn">Submit</button>
</form>
{% endblock %}
I made sure to have the enctype be "multipart/form-data" but when I go to actually execute the upload, it straight up skips the file, or if I have any validation in there, it rejects all validation. It's as if the file is never even there.
The software I use is:
- Flask-WTF == 0.12
- Flask == 0.10.1
is there any reason as to why it's bugging out like this?