S
S
Stanislav Nekrasov2019-02-21 15:18:34
Python
Stanislav Nekrasov, 2019-02-21 15:18:34

How to make sure that there is a correct encoding (Python, Flask)?

Hello.
I write the code for returning the main page:

@app.route("/")
def get_index():
    with open("index.html", "r") as file:
        return file.read()

But for some reason, something strange is shown in the browser instead of normal Russian characters.
For example, instead Клиентof showing Клиент.
If you just open the index.html file in the browser, then everything is fine.
Same with other files. Files encoded in UTF-8.
What to do?
PS I didn't do anything extra in the code, the code is also in UTF-8 encoding.
UPD: The html file says<meta charset="utf-8">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Nekrasov, 2019-02-21
@Metalofon

Basically, I wrote this:

@app.route("/")
def get_index():
    with open("index.html", "r", encoding="utf-8") as file:
        return file.read()

And it worked. (I tracked that the file is not read correctly on the server.)
And earlier I wrote the same way, but it didn't work...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question