GithubHelp home page GithubHelp logo

sn-ugani-prestolnico's Introduction

How to run webapp2 without Cloud SDK

If you can't get Google Cloud SDK to run on your computer, you can still use the webapp2 Python framework without the Cloud SDK. This is a step-by-step tutorial on how to do it.

Step 1: Create new PyCharm project

Open PyCharm and click on Create New Project.

PyCharm Create New Project Window

Step 2 (optional): Create a virtual environment

In the next step define the project path and optionally create a virtual environment.

Create a virtual environment

Step 3: Install PIP libraries

Now that you've started a new project, open the Terminal tab (below) and install three PIP libraries with the following commands:

  • pip install WebOb
  • pip install Paste
  • pip install webapp2

webapp2 is the Python framework we'll use and it needs WebOb in order to work correctly. Paste is a HTTP server that we'll use to run our website on our computer.

Install libraries via PIP

Step 4: Create main.py

Create a file called main.py in the root of your project.

Then add the following code in it:

import webapp2


# handlers
class MainHandler(webapp2.RequestHandler):
    def get(self):
        return self.response.write('Hello, SmartNinja!')
	
	
# URLs
app = webapp2.WSGIApplication([
    webapp2.Route('/', MainHandler),
], debug=True)
	
	
# run the localhost server
localhost = True  # change to False before deploying to Google Cloud (GAE)
if localhost:
    def main():
        from paste import httpserver
        httpserver.serve(app, host='localhost', port='8080')


    if __name__ == '__main__':
        main()

Step 5: Run your web app

Now you can finally run your new web app! Right-click on main.py and select Run 'main'.

Run main.py

Step 6: See your web app in browser

A new window will open in your PyCharm below. Click on the http://localhost:8080 link and your web app will open in the browser.

Step 7: Make some changes

Change "Hello, SmartNinja!" into something else, for example "Hello, Your Name!". When you do this change, you'll have to reload both main.py and your browser to see the changes.

Click on the green curved arrow to reload main.py:

Reload app

Congrats

That's it! You've successfully set up a localhost web app. :)

Step 8 (bonus): Deploy to Google Cloud (App Engine)

Even if the Cloud SDK does not work on your computer, you can still deploy this web app on Google Cloud (on Google App Engine). See this tutorial to learn how: click here.

sn-ugani-prestolnico's People

Contributors

geca avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.