Reputation: 21
I'm following the second chapter in "Google App Engine With Python" and I've copied the code exactly like it is in the book, but I get a blank page when I try to open it now and it's giving me the following error:
ImportError: <module 'main' from '...../clock/main.pyc'> has no attribute application
I noticed it says main.pyc at the end there, it should be using main.py. Is this some kind of automatically generated file?
app.yaml
application: clock
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.application
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: "2.9.6"
- name: markupsafe
version: "0.15"
main.py
import datetime
import jinja2
import os
import webapp2
from google.appengine.api import users
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd()))
class MainPage(webapp2.RequestHandler):
def get(self):
current_time = datetime.datetime.now()
user = users.get_current_user()
login_url = users.create_login_url(self.request.path)
logout_url = users.create_logout_url(self.request.path)
template = template_env.get_template('home.html')
context = {
'current_time': current_time,
'user': user,
'login_url': login_url,
'logout_url': logout_url,
}
self.response.out.write(template.render(context))
application = webapp2.WSGIApplication([('/', MainPage)], debug=True)
Appreciate any help.
Upvotes: 0
Views: 176
Reputation: 55924
The line
application = webapp2.WSGIApplication([('/', MainPage)], debug=True)
should not be indented; as coded, it is part of the class MainPage
's get
method, but it should be a module level variable, so not indented at all.
Upvotes: 1