Google App Engine – the first experiences
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.