2017-12-14 14 views
-3
I am trying to upload file. the abnormal is 'The method is not allowed for the requested URL' after run . However my code is request methods is 'POST' 

のために許可されていませんこれは私のhtmlです:フラスコファイルのアップロード、方法が要求されたURL

<form action="" enctype='multipart/form-data' method="POST"> 
<span class="btn btn-info" id="import"> 
    <input type="file" name="file"> 
    </span>input type="submit" value="upload" id="submit"> 

これは私のAPIコードです:

@api.route('/upload', methods=['POST','GET']) 
def upload(): 
    if request.method == 'POST': 
     file = request.files['file'] 
     upload_path = os.path.join(APP_STATIC_TXT, secure_filename(file.filename)) 
     file.save(upload_path) 
     return redirect(url_for('/')) 

この実行結果:

INFO: werkzeug:127.0.0.1 - - [14/Dec/2017 16:26:42] "POST /api/v1.0/upload HTTP/1.1" 400 - INFO:werkzeug:127.0.0.1 - - [14/Dec/2017 16:26:42] "POST/HTTP/1.1" 405 - INFO:werkzeug: * Detected change in '/home/python/Desktop/VCG/vcg/api_1_0/test01.py', reloading

これは、Web htmlです:

Method Not Allowed 

方法は、要求されたURLに許可されていません。

+0

ここにコードを入れて、正しくフォーマットしてください。 –

答えて

0

formactionの属性には、current view urlを使用しています。 url_for('upload')

+0

これを/ uploadに変更した後も、それでもうまくいかない、というエラーはエラーです:werkzeug:要求時エラー: "File/usr/lib/python2。 ( "%s:%s \ r \ n"%(キーワード、値))とIOError:[Errno 32]破損したパイプを削除します。 –

+0

'file'を印刷できますか? –

+0

ファイルを印刷できません –

関連する問題