It's weird: I tried that on my machine and is working fine -- even without the __init__.py file inside templates. What version of web.py are you using? --Matteo
On Mon, Dec 23, 2013 at 3:38 PM, Keith <[email protected]> wrote: > I can't for the life of me get this simple template example to work, which > can be seen here: http://webpy.org/docs/0.3/tutorial > > Here's the project layout: > > $ find . > . > ./code.py > ./code.pyc > ./templates > ./templates/index.html > > Contents of code.py: > > $ cat code.py > import web > > render = web.template.render('templates/') > > urls = ( > '/', 'index' > ) > > class index: > def GET(self): > name = 'test' > return render.index(name) > > if __name__ == '__main__': > app = web.application(urls, globals()) > app.run() > > Contents of templates/index.html: > > $ cat templates/index.html > $def with (name) > > hi $name > > When I run the test web server, it seems that "templates" is supposed to > be a Python package? I don't see in the docs or tutorial that it should > be... > > $ python code.py > > Traceback (most recent call last): > > File "code.py", line 3, in <module> > > render = web.template.render('templates/') > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/template.py", > line 1036, in __init__ > self.mod = __import__(name, None, None, ['x']) > > ImportError: No module named templates > > > I tried to make that a package: > > $ find . > . > ./code.py > ./code.pyc > ./templates > ./templates/index.html > ./templates/__init__.py > > Web server starts now: > > $ python code.py > http://0.0.0.0:8080/ > > But when I try to view the page, I get a 500: > > Traceback (most recent call last): > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/application.py", > line 239, in process > return self.handle() > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/application.py", > line 230, in handle > return self._delegate(fn, self.fvars, args) > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/application.py", > line 420, in _delegate > return handle_class(cls) > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/application.py", > line 396, in handle_class > return tocall(*args) > > File "/home/keith/projects/webpy/code.py", line 13, in GET > > return render.index(name) > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/template.py", > line 1017, in __getattr__ > t = self._template(name) > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/template.py", > line 1014, in _template > return self._load_template(name) > > File > "/home/keith/env/webpy/local/lib/python2.7/site-packages/web/template.py", > line 1043, in _load_template > t = getattr(self.mod, name) > > AttributeError: 'module' object has no attribute 'index' > > > > 127.0.0.1:51132 - - [23/Dec/2013 09:35:06] "HTTP/1.1 GET /" - 500 > Internal Server Error > > What is the correct way to use templates in this case? > > Keith > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/webpy. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "web.py" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/webpy. For more options, visit https://groups.google.com/groups/opt_out.
