I'm working to modify a cookiecutter Flask app.
I have a form built into the public/flat template that looks like:
<form class="form-inline" id="registerForm" method="POST" action="/get_email/" role="form">
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address">
</div>
<button type="submit" class="btn btn-warning btn-lg">submitMe!</button>
</form>
My public blueprint contains:
blueprint = Blueprint('public', __name__, static_folder="../static")
@login_manager.user_loader
def load_user(id):
return User.get_by_id(int(id))
@blueprint.route("/", methods=["GET"])
def flat():
return render_template('public/flat.html')
@blueprint.route("/get_email/", methods=['GET', 'POST'])
def get_email():
email = request.get_data()
return email
When I tested the email signup form (html above) by submitting only the email, In my debugger I get :
email = ''
In the firefox net panel I see:
POST /get_email/
400 BAD REQUEST
127.0.0.1:5000
192 B
127.0.0.1:5000
31ms
HeadersPostResponseHTMLCacheCookies
view source
Content-Length
192
Content-Type
text/html
Date
Thu, 04 Feb 2016 17:58:42 GMT
Server
Werkzeug/0.10.4 Python/2.7.5
Set-Cookie
session=eyJfaWQiOnsiIGIiOiJPVEprT1RsaU5ESXpNamMzTmpjMk5ESmpORGs1WmpGaFlXRTRObVpsWWpJPSJ9fQ.CZUi0g.mHrFfzFfFsX9PIjQmeN-3GQ1c2Y
; HttpOnly; Path=/
view source
Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding
gzip, deflate
Accept-Language
en-US,en;q=0.5
Connection
keep-alive
Cookie
csrftoken=kvecASUkun0BdgnLvf87MsW2hiARhVhr; session=eyJfaWQiOnsiIGIiOiJPVEprT1RsaU5ESXpNamMzTmpjMk5ESmpORGs1WmpGaFlXRTRObVpsWWpJPSJ9fQ
.CZUizg.9ZEEVV-XujIY8RQdK1Wk9cwC90M
Host
127.0.0.1:5000
Referer
http://127.0.0.1:5000/
User-Agent
Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0
Content-Length
0
Content-Type
application/x-www-form-urlencoded
Why is the post not working?