Just starting out with Flask and Python. I have a simple form that does an ajax post using the jQuery ajax form library. It goes to a function on the python side and add's a user to a mongoDb database. It then returns a true or false.
Upon returning the boolean I get this error:
TypeError: 'bool' object is not iterable
Most recent traceback:
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response)
Python side
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'GET':
return render_template('signup.html')
if request.method == 'POST':
result = create_user(request.form["firstname"],
request.form["lastname"],
request.form["username"],
request.form["password"],
request.form["email"])
return jsonify(result)
Javascript
<script type="application/javascript">
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#signupform').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>
Create_User Function
def create_user(form_first_name, form_last_name, form_username, form_password, form_email):
user = User()
user.first_name = form_first_name
user.last_name = form_last_name
user.last_modified = datetime.now()
user.username = form_username
user.password = form_password
user.email = form_email
if user.save():
return True
else:
return False