On Thu, Jul 12, 2012 at 2:50 PM, soujiro0725 <[email protected]> wrote:

> AppEngine for Python SDK latest
>
> Hi, I'm trying to separate the program into many files.  In order to do
> so, I need to put "import handler" for handler.py file if I'm correct.
>
> But for some reason, I keep getting errors.
>

I think you've got two options..

change "import handler" to "from handler import Handler"

or

change "class MainPage(Handler):" to "class MainPage(handler.Handler):"

cheers,

J



>
> main.py is
>
> import webapp2
>> import os
>> import jinja2
>> import handler
>>
>> template_dir = os.path.join(os.path.dirname(__file__), 'templates')
>> jinja_env = jinja2.Environment(loader =
>> jinja2.FileSystemLoader(template_dir),
>>                                autoescape = True)
>> def render_str(template, **params):
>>     t = jinja_env.get_template(template)
>>     return t.render(params)
>> def make_secure_val(val):
>>     return '%s|%s' % (val, hmac.new(secret, val).hexdigest())
>> def check_secure_val(secure_val):
>>     val = secure_val.split('|')[0]
>>     if secure_val == make_secure_val(val):
>>         return val
>> class MainPage(Handler):
>>     def get(self):
>>         self.response.headers['Content-Type'] = 'text/plain'
>>         self.render('front.html', wikis = wikis[0], time =
>> int(diff.total_seconds()))
>> app = webapp2.WSGIApplication([('/?', MainPage)], debug=True)
>
>
>  handler.py is
>
> import webapp2
>> class Handler(webapp2.RequestHandler):
>>     def write(self, *a, **kw):
>>         self.response.out.write(*a, **kw)
>>     def render_str(self, template, **params):
>>         params['user'] = self.user
>>         return render_str(template, **params)
>>     def render(self, template, **kw):
>>         self.write(self.render_str(template, **kw))
>>     def set_secure_cookie(self, name, val):
>>         cookie_val = make_secure_val(val)
>>         self.response.headers.add_header(
>>             'Set-Cookie',
>>             '%s=%s; Path=/' % (name, cookie_val))
>>     def read_secure_cookie(self, name):
>>         cookie_val = self.request.cookies.get(name)
>>         return cookie_val and check_secure_val(cookie_val)
>>     def login(self, user):
>>         self.set_secure_cookie('user_id', str(user.key().id()))
>>     def logout(self):
>>         self.response.headers.add_header('Set-Cookie', 'user_id=; Path=/')
>>     def initialize(self, *a, **kw):
>>         webapp2.RequestHandler.initialize(self, *a, **kw)
>>         uid = self.read_secure_cookie('user_id')
>>         self.user = uid and User.by_id(int(uid))
>
>
> This raises an error,
>
>   File "/Users/ishidasouichi/appengine_python/chword/main.py", line 28, in
>> <module>
>>     class MainPage(Handler):
>> NameError: name 'Handler' is not defined
>> INFO     2012-07-12 04:40:05,243 dev_appserver.py:2904] "GET /favicon.ico
>> HTTP/1.1" 500 -
>
>
> Looks like main.py is not reading handler.py at all.
>
> Could anyone point out the mistake I am making?
>
> soujiro0725
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/V4KbCWSLNBsJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>



-- 
Jason Galea
[email protected]

http://lecstor.com
https://github.com/lecstor
https://metacpan.org/author/LECSTOR
http://au.linkedin.com/in/jasongalea
https://plus.google.com/110776762575649383381
https://twitter.com/Lecstor

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to