2

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.

1
  • Are you using Python2 or Python3? Commented Jul 21, 2016 at 4:27

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

This fixed it. Thanks!
0

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.