Reputation: 523
Error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 24: ordinal not in range(128)
So basically I have a Flask app where users fill a sign up form and it renders a new page.
Here's the code:
render_template('signUpSuccess.html', password="You should know, right? π")
It's not a serious project just a practice app I'm creating since I'm learning Python. I'm positive it's because of the emoji. I've tried other SO questions but just can't figure it out. I know the emoji is not necessary but It'd be nice to know how I can fix this in the future.
Upvotes: 2
Views: 6954
Reputation: 913
You should decode that string. Try this:
the_password = "You should know, right? π"
the_password = the_password.decode('utf-8')
render_template('signUpSuccess.html', password=the_password)
Upvotes: 0
Reputation: 168616
Try passing a unicode
object, not a str
into render_template()
, like so:
render_template('signUpSuccess.html', password=u"You should know, right? π")
Sample program:
# coding: utf-8
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def root():
return render_template('signUpSuccess.html', password=u"You should know, right? π")
if __name__=="__main__":
app.run(debug=True)
template:
<html>password: {{ password }}</html>
Upvotes: 1