2012-08-29 21 views
41

Sadece Flask'ı öğrenmeye başladım ve bir POST yöntemine izin verecek bir form oluşturmaya çalışıyorum.Flask - POST Hatası 405 Yöntem Kullanılmıyor

@app.route('/template', methods=['GET', 'POST']) 
def template(): 
    if request.method == 'POST': 
     return "Hello" 
    return render_template('index.html') 

Ve index.html:

<html> 
    <head> 
    <title> Title </title> 
    </head> 
    <body> 
    Enter Python to execute: 
    <form action="/" method="post"> 
     <input type="text" name="expression" /> 
     <input type="submit" value="Execute" /> 
    </form> 
    </body> 
</html> 

çalışıyor (Bu GET aldığında bunu render) formu yükleniyor İşte benim yöntemidir. Ancak gönder düğmesine tıkladığımda, POST 405 hatası Metod İzin Verilmiyor. Neden gösterilmiyor?

cevap

32

yöntem bu bir yazım hatası olduğu sürece, template manzaraya işaret edecek şekilde formun action niteliğini ayarlamalısınız /template için yönlendirildiğinde Formunuz / göndererek edilir: Değiştir action="{{ url_for('template') }}"

11

:

<form action="/" method="post"> 

ile:

<form action="{{ url_for('template') }}" method="post"> 
4

Eğeratlarsanızözniteliği, form geçerli URL'ye gönderilecek.

değiştirin:

<form action="/" method="post"> 

ile:

<form method="post">