python - Web.py Template Not Found -


i followed this tutorial test mysql web.py setup.

as tutorial has no complete source code post mine here:

import web import mysqldb  web.config.debug = false  urls = (   '/login', 'login',   '/reset', 'reset', ) app = web.application(urls, locals()) db = web.database(dbn='mysql', db='dbname', user='user', pw='password')  store = web.session.diskstore('sessions') session = web.session.session(app, store,                               initializer={'login': 0, 'privilege': 0})  def logged():         if session.login==1:             return true         else:             return false def create_render(privilege):     if logged():         if privilege == 0:             render = web.template.render('/users/me/desktop/cpage/templates/reader')         elif privilege == 1:             render = web.template.render('/users/me/desktop/cpage/templates/user')         elif privilege == 2:             render = web.template.render('/users/me/desktop/cpage/templates/admin')         else:             render = web.template.render('/users/me/desktop/cpage/templates/communs')     else:         render = web.template.render('/users/me/desktop/cpage/templates/login')     return render class login:     def get(self):         if logged():             render = create_render(session.privilege)             return '%s' % render.login_double()         else:             render = create_render(session.privilege)             return '%s' % render.login()     def post(self):         name, passwd = web.input().name, web.input().passwd         ident = db.select('example_users', where='name=$name', vars=locals())[0]         try:             if hashlib.sha1("salt754-"+passwd).hexdigest() == ident['pass']:                 session.login = 1                 session.privilege = ident['privilege']                 render = create_render(session.privilege)                 return render.login_ok()             else:                 session.login = 0                 session.privilege = 0                 render = create_render(session.privilege)                 return render.login_error()         except:             session.login = 0             session.privilege = 0             render = create_render(session.privilege)             return render.login_error() class reset:     def get(self):         session.login = 0         session.kill()         render = create_render(session.privilege)         return render.logout()  if __name__ == "__main__":     app.run() 

the directory cpage on desktop contains follows:

dbtest.py templates login.html sessions

in templates there login.html, sure there because problem face is: server able start terminal (i'm running macosx mavericks) whenever enter localhost:port/login crashes:

http://0.0.0.0:1234/ traceback (most recent call last):   file "/library/python/2.7/site-packages/web/application.py", line 239, in process     return self.handle()   file "/library/python/2.7/site-packages/web/application.py", line 230, in handle     return self._delegate(fn, self.fvars, args)   file "/library/python/2.7/site-packages/web/application.py", line 420, in _delegate     return handle_class(cls)   file "/library/python/2.7/site-packages/web/application.py", line 396, in handle_class     return tocall(*args)   file "cpage/dbtest.py", line 48, in     return '%s' % render.login()   file "/library/python/2.7/site-packages/web/template.py", line 1017, in __getattr__     t = self._template(name)   file "/library/python/2.7/site-packages/web/template.py", line 1011, in _template     self._cache[name] = self._load_template(name)   file "/library/python/2.7/site-packages/web/template.py", line 1001, in _load_template     raise attributeerror, "no template named " + name attributeerror: no template named login 

okay figured out myself, best way learn stuff. either way wanted provide world answer.

first of code tutorial had bit different, post helped me lot.

after taking using code (or better: merging it) had same problem.

i had re-organize folder structure. adding layout.html templates folder fixed problem. important use right path directory.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -