How to import modules in Google App Engine?
original source : http://stackoverflow.com/questions/2710861/how-to-import-modules-in-google-app-engine
Simply place the
short_url.py file in your app’s directory.
Sample App Engine project:
views.py (or wherever), you can then import like so:
For more complex projects, perhaps a better method is to create a directory especially for dependencies; say
from lib import short_url
Apologies, I should have mentioned this earlier. You need modify your path, thanks to Nick Johnson for the following fix.
Ensure that this code is run before starting up your app; something like this:
# credit: Nick Johnson of Google
url_map = [ ('/', views.IndexHandler),] # etc.
app = webapp.WSGIApplication(url_map, debug=False)
if __name__ == "__main__":
To get this code to run before all other imports, you can put the path managing code in a file of its own in your app’s base directory (Python recognizes everything in that directory without any path modifications).
And then you’d just ensure that this import
…is listed before all other imports in your
Here’s a link to full, working example in case my explanation wasn’t clear.