Web.py + jinja2

120 views
Skip to first unread message

Aleksandr Rozhkov

unread,
Aug 28, 2012, 9:33:02 AM8/28/12
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?

Primoz Anzur

unread,
Aug 28, 2012, 10:12:44 AM8/28/12
to we...@googlegroups.com
Wrong content-type?


--
You received this message because you are subscribed to the Google Groups "web.py" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/PQTPTf90jcoJ.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.


Aleksandr Rozhkov

unread,
Aug 28, 2012, 6:00:36 PM8/28/12
to we...@googlegroups.com
Tried to set, didn't work. In source code of page my template code wrap into tag pre. 


вторник, 28 августа 2012 г., 18:12:57 UTC+4 пользователь Primoz Anzur написал:

Aleksandr Rozhkov

unread,
Aug 28, 2012, 6:05:22 PM8/28/12
to we...@googlegroups.com
web.header() helps, thx!
Reply all
Reply to author
Forward
0 new messages