1 .. _tutorials.quickstart.nogae: 2 3 Quick start (to use webapp2 outside of App Engine) 4 ================================================== 5 webapp2 can also be used outside of App Engine as a general purpose web 6 framework, as it has these features: 7 8 - It is independent of the App Engine SDK. If the SDK is not found, it sets 9 fallbacks to be used outside of App Engine. 10 - It supports threaded environments through the module :ref:`api.webapp2_extras.local`. 11 - All webapp2_extras modules are designed to be thread-safe. 12 - It is compatible with ``WebOb`` 1.0 and superior, which fixes several bugs 13 found in the version bundled with the SDK (which is of course supported as 14 well). 15 16 It won't support App Engine services, but if you like webapp, why not use it 17 in other servers as well? Here we'll describe how to do this. 18 19 .. note:: 20 If you want to use webapp2 on App Engine, 21 read the :ref:`tutorials.quickstart` tutorial instead. 22 23 24 Prerequisites 25 ------------- 26 If you don't have a package installer in your system yet (like ``pip`` or 27 ``easy_install``), install one. See :ref:`tutorials.installing.packages`. 28 29 If you don't have ``virtualenv`` installed in your system yet, install it. 30 See :ref:`tutorials.virtualenv`. 31 32 33 Create a directory for your app 34 ------------------------------- 35 Create a directory ``hellowebapp2`` for your new app. It is where you will 36 setup the environment and create your application. 37 38 39 Install WebOb, Paste and webapp2 40 -------------------------------- 41 We need three libraries to use webapp2: `WebOb <http://pypi.python.org/pypi/WebOb>`_, for Request and Response objects, 42 `Paste <http://pypi.python.org/pypi/Paste>`_, for the development server, 43 and `webapp2 <http://pypi.python.org/pypi/webapp2>`_ itself. 44 45 Type this to install them using the **active virtual environment** 46 (see :ref:`tutorials.virtualenv`): 47 48 .. code-block:: text 49 50 $ pip install WebOb 51 $ pip install Paste 52 $ pip install webapp2 53 54 Or, using easy_install: 55 56 .. code-block:: text 57 58 $ easy_install WebOb 59 $ easy_install Paste 60 $ easy_install webapp2 61 62 Now the environment is ready for your first app. 63 64 65 Hello, webapp2! 66 --------------- 67 Create a file ``main.py`` inside your ``hellowebapp2`` directory and define 68 a handler to display a 'Hello, webapp2!' message. This will be our bootstrap 69 file:: 70 71 import webapp2 72 73 class HelloWebapp2(webapp2.RequestHandler): 74 def get(self): 75 self.response.write('Hello, webapp2!') 76 77 app = webapp2.WSGIApplication([ 78 ('/', HelloWebapp2), 79 ], debug=True) 80 81 def main(): 82 from paste import httpserver 83 httpserver.serve(app, host='127.0.0.1', port='8080') 84 85 if __name__ == '__main__': 86 main() 87 88 89 Test your app 90 ------------- 91 Now start the development server using the Python executable provided by 92 virtualenv: 93 94 .. code-block:: text 95 96 $ python main.py 97 98 The web server is now running, listening for requests on port 8080. You can 99 test the application by visiting the following URL in your web browser: 100 101 http://127.0.0.1:8080/ 102