Installation:
- install python 2.7 Get it from here: https://code.google.com/p/pythonxy/wiki/Downloads?tm=2
- install app engine sdk. get it from https://developers.google.com/appengine/downloads
- download gdata from https://code.google.com/p/gdata-python-client/downloads/list
- install git for windows from http://git-scm.com/download/win
- install unittest2 from https://pypi.python.org/pypi/unittest2 (to install: python.exe setup.py install)
- install python tools for visual studio from http://pytools.codeplex.com/releases/view/82132
Setting up your project:
- Create a directory
- Create two files main.py and app.yaml
app.yaml:application: mytestapp
version: 1
runtime: python27
threadsafe: true
api_version: 1
default_expiration: "5d 12h"handlers:
- url: /.*
script: main.app
main.py:
import webapp2class Index(webapp2.RequestHandler):
def get(self):
self.response.out.write('hello world!')mappings = [('/', 'main.Index')]
app = webapp2.WSGIApplication(mappings)
- Launch VS. File->New->Project->Python Templates->From Existing Python Code
- Add above two files to the project
- Alt->ENTER->General. Set Startup File to C:\Program Files (x86)\Google\google_appengine\dev_appserver.py
- Alt->ENTER->Debug. Set Script Arguments to directory in step 1
- F5
- You will get a ZipImportError. Fix it using this link: http://pytools.codeplex.com/discussions/265255
- Verify this output in python shell:
INFO 2013-03-10 15:07:15,349 appcfg.py:618] Checking for updates to the SDK.INFO 2013-03-10 15:07:16,717 appcfg.py:636] The SDK is up to date.
WARNING 2013-03-10 15:07:16,720 dev_appserver.py:3578] The datastore file stub
is deprecated, and
will stop being the default in a future release.
Append the –use_sqlite flag to use the new SQLite stub.You can port your existing data using the –port_sqlite_data flag or
purge your previous test data with –clear_datastore.WARNING 2013-03-10 15:07:16,779 simple_search_stub.py:975] Could not read searc
h indexes from c:\users\me\appdata\local\temp\dev_appserver.searchindexes
INFO 2013-03-10 15:07:17,049 dev_appserver_multiprocess.py:656] Running appl
ication dev~mytestapp on port 8080: http://localhost:8080
INFO 2013-03-10 15:07:17,052 dev_appserver_multiprocess.py:658] Admin consol
e is available at: http://localhost:8080/_ah/admin - Open web browser, navigate to http://localhost:8080/
- Verify web page that says hello world!
-
Now to break above code (just for testing), simply change
mappings = [('/', 'main.Index')]
to
mappings = [('/', 'Index')]Now if you refresh the webpage, you will see:
500 Internal Server ErrorThe server has either erred or is incapable of performing the requested operation.
Python shell will show:
ERROR 2013-03-10 15:10:17,605 webapp2.py:1552] import_string() failed for ‘In
dex’. Possible reasons are:– missing __init__.py in a package;
– package or module path not included in sys.path;
– duplicated package or module name taking precedence in sys.path;
– missing module, class, function or variable;Original exception:
ImportError: No module named Index
Debugged import:
– ‘Index’ not found.
Traceback (most recent call last):
File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
.py”, line 1535, in __call__
rv = self.handle_exception(request, response, e)
File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
.py”, line 1529, in __call__
rv = self.router.dispatch(request, response)
File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
.py”, line 1272, in default_dispatcher
self.handlers[handler] = handler = import_string(handler)
File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
.py”, line 1852, in import_string
return __import__(import_name)
ImportStringError: import_string() failed for ‘Index’. Possible reasons are:– missing __init__.py in a package;
– package or module path not included in sys.path;
– duplicated package or module name taking precedence in sys.path;
– missing module, class, function or variable;Original exception:
ImportError: No module named Index
Debugged import:
– ‘Index’ not found.
INFO 2013-03-10 15:10:17,674 dev_appserver.py:3104] “GET / HTTP/1.1” 500 –