Reputation: 3
i dont know why this is happening but i have tried alot but still i m getting the same output in my browser.. i m running this code here i am trying to inherit the handle class instances to my another class.. i am running my code in using google app engine in chrome browser.. whole process is similar as show by udacity instructor else the rot13 code ..
import os
import codecs
import webapp2
import jinja2
#from check import valid_month
#from check import valid_year
#from check import valid_day
template_dir = os.path.join(os.path.dirname(__file__),'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape= True)
class Handler(webapp2.RequestHandler):
"""docstring for Handler"""
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self,template,**kw):
self.write(self.render_str(template, **kw))
class Secondhandler(Handler):
def get(self):
key = self.request.get_all("name")
name = ''.join(key)
new = codecs.encode(name, 'rot13')
self.render("shopping_list.html", name = new )
app = webapp2.WSGIApplication([
('/',Handler)
], debug=True)
as you can see my second handler is named secondhandler which inherit from its parent class named handler.. but when i view this in my browser it throws an error , my shopping list.html is as follows
<form>
<h2>tell us what you like</h2>
<br>
<textarea name='name' type='text'>{{name}}</textarea>
<br>
<br>
<button>add</button>
</form>
most important thing is that i dont think tht there is any indentation issue as when i run my code by using the whole get in just main handler it works fine .. but still i am unable to use secondhanlder .. heres my code without class secondhandler .. and it prints and works rot13 nicely..
import os
import codecs
import webapp2
import jinja2
#from check import valid_month
#from check import valid_year
#from check import valid_day
template_dir = os.path.join(os.path.dirname(__file__),'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape= True)
class Handler(webapp2.RequestHandler):
"""docstring for Handler"""
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self,template,**kw):
self.write(self.render_str(template, **kw))
def get(self):
key = self.request.get_all("name")
name = ''.join(key)
new = codecs.encode(name, 'rot13')
self.render("shopping_list.html", name = new )
#class Secondhandler(Handler):
app = webapp2.WSGIApplication([
('/',Handler)
], debug=True)
Upvotes: 0
Views: 85
Reputation: 1270
It doesn't look like you've registered SecondHandler
:
app = webapp2.WSGIApplication([
('/',Handler)
], debug=True)
What happens when you change Handler
in that block to SecondHandler
instead?
Upvotes: 3