0
해당 열을 선택하여 MySQL에 csv 파일을 업로드하려고하는데 문제가되면 경로가 변경되면 파일이 닫힙니다. 그래서 같은 경로에 두 개의 템플릿을 렌더링하려했습니다. 첫 번째는 파일을로드하고 두 번째는 열을 선택합니다. 첫 번째 템플릿에만 액세스 할 수 있습니다. 내가 함께 두 번째 양식을 테스트입니다 (env.is_submitted)하지만 난 그것을플라스크 다른 파일에 두 가지 양식을 렌더링하지만 첫 번째 양식을 얻을 수 있습니다.
@app.route('/upload', methods=['GET', 'POST'])
def upload():
form = UploadForm()
global columnscsv, salessource
if form.validate_on_submit():
try:
filename = secure_filename(form.csv.data.filename)
file = form.csv.data
if file and allowed_file(filename):
print 'file_path'
salessource = CSVSource(file, delimiter=',')
columnscsv = salessource.fieldnames
print columnscsv
finally:
return render(salessource)
return render_template('upload.html', form=form)
def render(salessource):
env = envForm()
if env.is_submitted():
print "submitted"
return render_template('form.html',columnscsv = columnscsv ,env =env)
하고 Upload.html
<html>
<head>
<title>Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" >
{{ form.hidden_tag() }}
{{ form.csv }}
<input type="submit">
</form></body>
</html>
{% block body %}
<form name = "mapping" method="POST" enctype="multipart/form-data" >
{{ env.hidden_tag() }}
<table>
{% for csv in columnscsv %}
<tr> <td> {{ csv }}</td>
<td><select name = "{{ csv }}" >
<option >year </option>
<option >month</option>
<option >day</option>
<option>reference</option>
<option>designation</option>
</select></td>
</tr>
{% endfor %}
</table>
<input type="submit" value="Submit" name = "submit" >
</form>
{% endblock %}
form.html "제출"인쇄합니다 제출하고 있지 않다하더라도
고마워요.하지만 여전히 모르겠어요. 어떻게 form.html의 폼에 접근 할 수 있습니까? – nourelhouda
'액세스'에 대한 더 자세한 정보가 있습니까? –
템플릿을 'form.hml'로 렌더링하면 의미가 없습니다. 양식의 태그를 가져옵니다. 그럼 다른 해결책을 찾았습니다. 파일을 로컬로 업로드하고 다시 사용합니다. 고맙습니다 – nourelhouda