Google App Engine – the first experiences

January 26th, 2010 | Tagged as , ,

A few days ago, I started to work on the corporatepoems.com website. The web is a fun pet project, an idea born somewhere in a pub after a few beers – I will write about the idea a bit later. Today, I just wanted to briefly comment on two problems which I encountered during my first steps with the App Engine.

Occasional blank pages

If you see a blank page when refreshing your app in a browser after a source code update, be it on your local machine or after the upload to Google, but then with any subsequent refresh the page appearing just fine, check the Python script executed for given URL (see your app.yaml) to make sure that you are invoking the main() function correctly, i.e. something like the notorious

if __name__ == '__main__':
	main()

If you make a typo in the above snippet or should you omit it completely, you will experience the problem above.

Update: See the comments below this article for explanation of the reason of this behavior.

Static files: CSS not loading

At some stage of working on the project I introduced the CSS style sheet for the site: added a static_dir to handlers section of the app.yaml file and then created the CSS file and stored it in the directory referred to by static_dir. Then, I simply referenced the CSS file in the HTML. So my app.yaml looked like

application: corporatepoems
version: 5
runtime: python
api_version: 1

handlers:
- url: /css
  static_dir: css

- url: /.*
  script: corporatepoems.py

…and the HTML contained:

<link rel="stylesheet" href="/css/corporatepoems.css" type="text/css" media="screen" />

However, the CSS would not load. I double checked the file and directory names, all was correct. The fix to the problem was to actually increase (or chage) the application version in the app.yaml file. After that, CSS loaded as expected. The explanation to this could be that I perhaps forgotten to save the app.yaml file after adding the static_dir at first place, but I’m pretty sure this was not the case. After the fix, I never saw the problem again.

All in all, working with Google App Engine and Python feels great so far, thanks Filip for your suggestion to give it a try! To be continued.

2 Comments

Fikovnik
January 27th, 2010 at 17:06

Thanks for sharing! Looking forward to next posts!

Nice design btw!

Ivo
March 7th, 2010 at 18:46

The reason for the first problem (occasional blank pages) became obvious to me now. Because of the typo in if __name__ == ‘main’, the condition never evaluated to true, thus main() function was not called upon the first invocation of the script. But any subsequent invocation of the script succeeded because of the app caching – the source code was not evaluated anymore, the App Engine called main() directly (the App Engine knew that main() was present in the script).

So the “strange” behavior of my app was entirely my mistake.

Your comment

You can post anonymous comments. Some tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>