Getting Started with Google App Engine on Windows (7, 8, 8.1)
Total Page:16
File Type:pdf, Size:1020Kb
Getting Started with Google App Engine on Windows (7, 8, 8.1) Note that this tutorial will not cover the App Engine Launcher! We’re only going to focus on the command line since being comfortable with it is crucial to being a web developer. In fact, very few tools even offer a GUI for you to use. Let’s get started! What this document will cover: 1. Installing Python 2.7 2. Installing Google App Engine 3. Deploying a “Hello, World” application using the command line Downloading Python Before you get started, we need to install Python. At the time of this writing, the latest release of Python 2 is 2.7.8. The version you download will depend on whether or not your PC is 32 or 64bit. To check, open up your Control Panel, then go to System and Security, and then click “View amount of RAM and processor speed”. You’ll see a screen like this: The look may vary slightly depending on your Windows version, but you should be able to see what kind of system you have. With that being said, now it’s time to download the Python installer from here. You’ll come to a screen like this: If you have a 32bit system, click the x86 MSI Installer. For 64bit PCs, use the x8664 link. Clicking this link will start downloading the Python installer to your computer! Installing Python Once Python is downloaded, open up the installer to begin. Run through the steps (leaving the defaults is okay). The only thing you’re going to want to change is this: when you get to the screen asking you to “Customize Python”, make sure you add Python to your system path by clicking the dropdown next to “Add python.exe to Path” and selecting the option to enable the entire feature. This will let us run Python from the command line easily. Once Python finishes installing, you can make sure that everything works by opening up PowerShell (a more advanced version of the Command Prompt) and typing “python”. You should get a screen like this if everything worked: If you didn’t get to this screen, feel free to look around online for more tutorials. Students who have signed up for the fullcourse experience can also email their coaches. Creating an App Engine Account First things first, you need to have a Google account for this (meaning an @gmail.com email address). If you don’t, set one up here. Once you have your Google account, you need to authorize that account for use with Google App Engine. You can do that by signing into your Google account here. Once you sign in, you should be taken to a screen like this: Click the “Create Application” button, and fill in all of the required details. Make sure you remember or write down your Application Identifier, because we’re going to need that URL when we deploy our app. Installing the SDK Go here and click the button for Python, and then select the link for Windows. This will download the App Engine installer for your PC. Once that download completes, open up the installer and go through it. Make sure to leave the “Add product path to user PATH” box checked, as that will let us run the server from the command line when we need to. Building your first application On your PC, create a folder called “helloworld”. Inside that folder, we’re going to put two files. The first is called app.yaml, and it is a configuration file for our project. Fill it in like this: application: yourappidentifier version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: url: /.* script: helloworld.app Make sure you fill in the “application” field with the application identifier from earlier! Next, we will need the actual app. Create a file called helloworld.py in the same folder that you created app.yaml. Inside of it, write this: import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['ContentType'] = 'text/plain' self.response.write('Hello, World!') app = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) You’ll learn more about what all of this means as you progress in the course. For now, just make sure that you have a folder called helloworld, and the two files from above inside of it. Time to test it out! Testing the app You’re all good to go at this point! Open up PowerShell, and run this command: python ‘C:\Program Files (x86)\Google\google_appengine\dev_appserver.py’ \path\to\helloworld Note that you may have to specify a different path to dev_appserver.py, depending on if your system is 64 or 32bit. Mine is a 64bit computer, so App Engine installed all of its files to the “Program Files (x86)” directory. All you are doing here is using Python to run the dev_appserver.py file, and passing in your helloworld directory as the app to run. If everything worked correctly, you should see some output on the command line like this: Then, you can go to http://localhost:8080 to see your app in action! Right now, it simply prints “Hello, World!” to the screen, but you’ll be making much more complex apps soon! Note that you can change the default port that App Engine uses by passing in a port=<port #> argument at the command line when you first start the server. For example, typing (all on one line): python ‘C:\Program Files (x86)\Google\google_appengine\dev_appserver.py’ \path\to\helloworld port=5000 would mean you go to http://localhost:5000 instead! You also get an “admin console” with your app that runs at http://localhost:8000 by default. Deploying your app Now that our app works, let’s push it to Google’s servers so we can reach it from any device like a normal website. To do this, we need to run another command called “appcfg” from PowerShell: python ‘C:\Program Files (x86)\Google\google_appengine\appcfg.py’ update \path\to\helloworld This will begin the upload process. You’ll need to enter your email address and Google account password. Once that completes, you’ll be able to go to http://yourappid.appspot.com to see your first App Engine site in action! .