1 .. _tutorials.quickstart: 2 3 Quick start 4 =========== 5 If you already know `webapp <http://code.google.com/appengine/docs/python/tools/webapp/>`_, 6 webapp2 is very easy to get started. You can use webapp2 exactly like webapp, 7 and learn the new features as you go. 8 9 If you are new to App Engine, read :ref:`tutorials.gettingstarted.index` first. 10 You will need the `App Engine SDK <http://code.google.com/appengine/docs/python/gettingstarted/devenvironment.html>`_ 11 installed for this quick start. 12 13 .. note:: 14 If you want to use webapp2 outside of App Engine, 15 read the :ref:`tutorials.quickstart.nogae` tutorial instead. 16 17 18 Create an application 19 --------------------- 20 Create a directory ``hellowebapp2`` for your new app. 21 `Download webapp2 <http://code.google.com/p/webapp-improved/downloads/list>`_, 22 unpack it and add ``webapp2.py`` to that directory. If you want to use extra 23 features such as sessions, extra routes, localization, internationalization 24 and more, also add the ``webapp2_extras`` directory to your app. 25 26 .. note:: 27 webapp2 is part of the Python 2.7 runtime since App Engine SDK 1.6.0, 28 so you don't need to upload it with your app anymore. To include it in 29 your app see 30 `Configuring Libraries <http://code.google.com/appengine/docs/python/python27/using27.html#Configuring_Libraries>`_. 31 32 Hello, webapp2! 33 --------------- 34 Create an ``app.yaml`` file in your app directory with the following contents: 35 36 .. code-block:: yaml 37 38 application: helloworld 39 version: 1 40 runtime: python27 41 api_version: 1 42 threadsafe: true 43 44 handlers: 45 - url: /.* 46 script: main.app 47 48 Then create a file ``main.py`` and define a handler to display a 49 'Hello, webapp2!' message:: 50 51 import webapp2 52 53 class HelloWebapp2(webapp2.RequestHandler): 54 def get(self): 55 self.response.write('Hello, webapp2!') 56 57 app = webapp2.WSGIApplication([ 58 ('/', HelloWebapp2), 59 ], debug=True) 60 61 62 Test your app 63 ------------- 64 If you're using the Google App Engine Launcher, you can set up the application 65 by selecting the **File** menu, **Add Existing Application...**, then selecting 66 the ``hellowebapp2`` directory. Select the application in the app list, click 67 the Run button to start the application, then click the Browse button to view 68 it. Clicking Browse simply loads (or reloads) 69 `http://localhost:8080/ <http://localhost:8080/>`_ in your default web browser. 70 71 If you're not using Google App Engine Launcher, start the web server with the 72 following command, giving it the path to the ``hellowebapp2`` directory: 73 74 .. code-block:: text 75 76 google_appengine/dev_appserver.py helloworld/ 77 78 The web server is now running, listening for requests on port 8080. You can 79 test the application by visiting the following URL in your web browser: 80 81 http://localhost:8080/ 82