Aleksandr Rozhkov
unread,Aug 28, 2012, 9:33:02 AM8/28/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to we...@googlegroups.com
Hello, i have some problem with jinja2 render. Browser shows up template file source with substituted values. There is my code.py:
-----------------------------------------------------------
import os
import web
import jinja2
from web import form
jaja = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__),'templates')))
login = form.Form(
form.Textbox('username', description = 'Ваше имя', id = 'username'),
form.Password('password'),
form.Button('login'),
)
urls = (
'/.*', 'index'
)
form
class index:
def GET(self):
template = jaja.get_template('index.html')
values = {'frm' : login.render(), 'name' : 'sasdasddfsdf'}
return template.render(values)
def POST(self):
i = web.input()
text = '%s, you login with password %s' % (i.username, i.password)
return text
if __name__ == "__main__":
app = web.application(urls,globals())
app.run()
------------------------------------------------------
And there is template index.html:
---------------------------------------------------------
<!DOCTYPE html>
<html>
<title>Login!</title>
<center>
<form method="POST">
{{frm}}
{{ name }}
</form>
</center>
</html>
--------------------------------------------------------
Where is my mistake?