Intro to Backend >> Templates >> Quiz: Writing Basic Form
Here is how to create a new application:
- Go to the folder in which you saved the last application, “hello-udacity”
- Create a new folder called “templates”
- Open up your code editor (ex: Sublime Text 2) and save a file called main.py into the templates folder you created in Step 2. I copied the text the teacher shows on the video for you. Here it is, it is what you will input into main.py:
import os import webapp2 class Handler(webapp2.RequestHandler): def write(self, *a, **kw): self.response.out.write(*a, **kw) class MainPage(Handler): def get(self): self.write("Hello, Udacity!") app = webapp2.WSGIApplication([('/', MainPage) ], debug=True)
- Save main.py. Create another file, save it as “app.yaml”. I copied the text the teacher shows from the video, with a slight change. See if you can find it. Input this into app.yaml:
application: templates version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: .* script: main.app
- Create one more file called “main.pyc”. Leave it blank.
- Open GoogleAppEngine Launcher if it is not already open. File >> Add Existing Application… Click “Browse”. Select the new folder templates you just made. Stop any other applications running by clicking them and then click Stop. Once all other applications are stopped (probably just the hello-udacity one is all you have to worry about), then click the templates one we just added, and click run. If it worked, you should be able to open it in Chrome with its local port:8080, while 8080 could be also 9080, or 10080, you need to look at Google AppEngine Launcher and look at templates to see the number associated with it. If it all worked, the page should say this:Hello, Udacity!