emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.06k stars 71 forks source link

regex and russian language in utf-8 template #217

Closed hloe0xff closed 4 years ago

hloe0xff commented 6 years ago

Hi, @gi0baro !

I'm cannot find nothing about regular expressions in templates, and when i create template with utf-8 encoding and write russian text, i cannot see a valid text on template rendering. Does weppy framework supports these features?

Sorry, if i ask stupid questions, and my english.

Thank you.

gi0baro commented 6 years ago

Hi @hloe0xff , don't worry about questioning everything! :)

Can you be more specific? The entire templating system just uses unicode internally and decode/encode from and to utf-8. Never had problems with chinese characters for instance. Are the strings coming from the route? Are directly written in template? Are they a python string inside the template ({{="foo"}})? Are you using the translator ({{=T("foo")}})?

Also regarding regexes, what do you want to do? I can't reply correctly without more information :)

hloe0xff commented 6 years ago

@gi0baro, i mean text directly written in template. No, i don't use a translator, where i may read about it?. But with tranlator i get error about invalid syntax.

I'm write in template next code: <caption>Русский текст!!! --- Russian text!!!</caption> Template encoding is UTF-8. Result on a attached picture. I'm using PyCharm IDE if is this important. current

About regexes. For example, i want extract substring from any variable or string.

gi0baro commented 6 years ago

@hloe0xff can you please try to change that line with:

<caption>{{="Русский текст!!!"}}</caption>

hloe0xff commented 6 years ago

Hello @gi0baro! Next code <caption>{{="Русский текст!!!"}}</caption>, render page:

current

gi0baro commented 6 years ago

@hloe0xff I can't reproduce your issue. Added this code to the bloggy example in index.html:

<p>py {{="Русский текст!!!"}}</p>
<p>translator {{=current.T("Русский текст!!!")}}</p>
<p>html Русский текст!!!</p>

Here is the result: image

python version? browser?

hloe0xff commented 6 years ago

@gi0baro Win7 + Python 3.6.5 + Latest Google Chrome

gi0baro commented 6 years ago

Super strange. Maybe is dependant on the encoding of your file-system but should use utf8 anyway. Can you try adding this line to your app:

app.config.templates_escape = 'all'

and see if anything changes?

hloe0xff commented 6 years ago
from weppy import App

app = App(__name__)
app2 = app.module(__name__, name='app2', url_prefix='app2')

app.config.templates_escape = 'all'

@app.route('/', methods='get')
def index():
    return dict(title='index')

@app2.route('/', methods='get')
def app2_index():
    return dict(title='app2 index')

if __name__ == '__main__':
    app.run(debug=True)

@gi0baro, no changes.

hloe0xff commented 6 years ago

Hi, @gi0baro!

Sorry for your lost time. I launch my project on a linux based operating system, and russian text shows correctly.

Project:

from weppy import App

app = App(__name__)
app.config.templates_escape = 'all'

@app.route('/')
def index():
    return dict(text='texxxt')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

Template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Привет, Мир!!!</h1>
<p>py {{="Русский текст!!!"}}</p>
<p>translator {{=current.T("Русский текст!!!")}}</p>
<p>html Русский текст!!!</p>
<p>{{="Русский текст!!!"}}</p>
</body>
</html>
gi0baro commented 6 years ago

@hloe0xff No worries! At least now I know it's a windows related issue. Will try to look at it.

hloe0xff commented 6 years ago

@gi0baro good luck and thank you for your products!