Thank you Andrei for you attention to my problem !
your post was helpful and it allowed me to progress :)
I modified the code this way, and suddenly this has partly solved the
problem of encoding:
My code.py
# ---------------------- code.py ----------------#
#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-
import web
from web import form
web.config.debug = False
#db = web.database(dbn='mysql', user='myname', pw='mypassword',
db='mydb')
db = web.database(dbn='mysql', user='eric', pw='bbmpo45', db='pygmee')
render = web.template.render('templates/')
urls = (
'/(.*)', 'index'
)
app = web.application(urls, globals())
class index:
"""
"""
def __init__(self):
""" """
def GET(self, name = "index"):
""" shows the home page """
# I try with those charsets without success
web.header("Content-Type", "text/html; charset= utf-8")
#web.header("Content-Type", "text/html; charset= iso-8859-1")
links = []
article =[]
# --- LINKS -
# All titles become links
result_titre_db = db.query('select titre from articles;')
for i in result_titre_db:
links.append(i.titre)
# --- ARTICLES -
# Andrei solution
result_article_db = db.query("select * from articles where
articles.titre = $title",vars=dict(title=name))
#result_article_db = db.query(query)
for i in result_article_db:
article.append(i.article)
return render.index(name, links, article)
if __name__ == "__main__":
app.run()
# -----------------------------------------------#
My charsetproblem.mysql
# -------- charsetproblem.mysql -----------------#
# Usage: mysql -u mylogin -p mybase < charsetproblem.mysql #
# Open : mysql -u mylogin -p mybase #
# mysql> SHOW TABLES; #
# mysql> select * from articles; #
# mysql> DROP TABLE IF EXISTS articles; #
#
#
# --- create table ---#
CREATE TABLE articles (
id int(10) NOT NULL auto_increment,
titre char(80) DEFAULT "" NOT NULL,
article text(4096) DEFAULT "" NOT NULL,
PRIMARY KEY (id)
)DEFAULT CHARACTER SET utf8;
# Note: i tried with and without DEFAULT CHARACTER SET utf8;#
# --- insert datas ---#
INSERT INTO articles VALUES (NULL, "simple link without french
characters", "Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.");
INSERT INTO articles VALUES (NULL, "simple link with frènch
chàracters", "Lorém ipsum dôlor sit amet, çonsèctetur àdipisicing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.");
# -----------------------------------------------#
My /templates/index.html
# -------------- index.html ---------------------#
$def with (name,links, article)
$# File: templates/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
</head>
<body>
<h3>$name.encode('iso-8859-1') </h3>
$for i in links:
<a href="$i">$i.encode('iso-8859-1') </a><br>
<em>
$for j in article:
$j.encode('iso-8859-1')
</em>
</body>
</html>
# -----------------------------------------------#
Result :
simple link with frènch chàracters
Lorém ipsum dôlor sit amet, çonsèctetur àdipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
I didn't change my db.py in /usr/lib/python2.5/site-packages/web/
db.py.
I left as it was.
But although the page is now displayed correctly without error,
there is a problem with the url that is written as :
http://127.0.0.1/simple%20link%20with%20fr%C3%83%C2%A8nch%20ch%C3%83%C2%A0racters
Have you an idea on how to solve this problem?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---