templates not working, no template named index

525 views
Skip to first unread message

globalrev

unread,
Apr 24, 2008, 4:46:33 PM4/24/08
to web.py
using wVista and python 2.5 and latest web.py

running:

$def with (name)

$if name:
I just wanted to say <em>hello</em> to $name.
$else:
<em>Hello</em>, world!


import web

render = web.template.render('templates/')

urls = (
'/', 'index')

##urls = (
## 'perspage', 'perspage')

class index:
def GET(self):
name = 'Bob'
print render.index(name)

class perspage:
def GET(self):
print "This is your superpersonal page"

class add:
def POST(self):
i = web.input()
n = web.insert('todo', title=i.title)
web.seeother('/')

web.webapi.internalerror = web.debugerror
if __name__ == "__main__": web.run(urls, globals())


results in:
Traceback (most recent call last):
File "C:\Python25\lib\site-packages\web\webapi.py", line 312, in
wsgifunc
result = func()
File "C:\Python25\lib\site-packages\web\request.py", line 131, in
<lambda>
func = lambda: handle(inp, fvars)
File "C:\Python25\lib\site-packages\web\request.py", line 61, in
handle
return tocall(*([x and urllib.unquote(x) for x in args] + fna))
File "C:/Python25/myPrograms/webapps/webexp2.py", line 14, in GET
print render.index(name)
File "C:\Python25\lib\site-packages\web\template.py", line 793, in
__getattr__
return self._do(p)
File "C:\Python25\lib\site-packages\web\template.py", line 780, in
_do
raise AttributeError, 'no template named ' + name
AttributeError: no template named index

127.0.0.1:51056 - - [24/Apr/2008 22:43:14] "HTTP/1.1 GET /" - 200 OK

globalrev

unread,
Apr 24, 2008, 4:51:19 PM4/24/08
to web.py
render = web.template.render('templates/')

templates/ has to be the windows path to the templates directory i
guess?

globalrev

unread,
Apr 24, 2008, 4:53:16 PM4/24/08
to web.py
render = web.template.render('C:\Python25\myPrograms\webapps
\templates')

aint wokring though

Bjorn Tipling

unread,
Apr 24, 2008, 5:38:47 PM4/24/08
to we...@googlegroups.com
templates/ is a relative path from where your script begins executing,
the code.py directory. so in this case it's probably in [PATH TO YOUR
code.py]/templates/.

globalrev

unread,
Apr 24, 2008, 5:46:28 PM4/24/08
to web.py
i have my script in webapps and then a directory templates which
contains the .html-file.
so then
render = web.template.render('C:\Python25\myPrograms\webapps
\templates')
should work but it doesnt.
it shouldnt be to the web.py template directory right?

Bjorn Tipling

unread,
Apr 24, 2008, 5:54:27 PM4/24/08
to we...@googlegroups.com
I'm not very good with windows paths, but why don't you just use a
relative path? 'templates/' doesn't work? What error are you getting?

Eric Talevich

unread,
Apr 24, 2008, 6:44:49 PM4/24/08
to web.py
Are you actually using

render = web.template.render('C:\Python25\myPrograms\webapps
\templates')

with the backslashes exactly like that? If so, Python would treat the
backslashes as string escapes. Try using a raw string ( r'C:
\Python25\myPrograms\webapps\templates' ), or replace the backslashes
with forward slashes (Windows understands both), or better yet, just
use the relative path ('templates/'). The relative path works for me
on on both Windows XP and OpenSuse, same code.

globalrev

unread,
Apr 24, 2008, 8:27:22 PM4/24/08
to web.py
well it works now when i used /.

but what is relative path?

Eric Talevich

unread,
Apr 25, 2008, 1:09:58 AM4/25/08
to web.py
So, it was just an issue of using Python strings with awkward Windows
paths.

http://en.wikipedia.org/wiki/Path_(computing)

On Windows, an absolute path starts with the drive letter ("C:\").
Anything else means relative to the current directory.
Reply all
Reply to author
Forward
0 new messages