Community

Simple hello world python flask app

Share this post:

Hey Y’all! Jeff here again, today we are going to be going through some really simple steps to get started deploying a simple hello world Python Flask app on Bluemix.

Flask is an awesome and really lightweight framework in Python to create powerful webapps. We are going to use it make a really simple hello world app in Python though.

In this post we are going to go through the written instructions on how to do it but if you prefer watching a video check out the video below.


In this tutorial we are going to go through two steps to deploy the app. One is a simple click a button to deploy to your app, we will go through that first. The second approach is a little more in depth and involves installing a command line tool to upload the application. This is great and preferred if you will be editing the code or you want to dig into the nuts and bolts of things.

Simple Getting Started Steps

Follow these simple steps to get started:

  1. Sign up for a Bluemix account, visit http://bluemix.net in your web browser and click “Sign-up” in the top right. We require a couple bits of information
  2. Wait for an email to arrive, it should only take a couple minutes. There should be a link in the email that says “Click here to complete your registration”, click that. Sign in with the username and password you created from step 1.
  3. Click the button below (this will deploy the app for you).
    Deploy to Bluemix
  4. You will come to a page that has a button called “Login”. Go ahead and click that.
  5. Next you will be taken to a page that asks you to create an alias. If my email address was jeff.davis251@gmail.com I would use jeffdavis251. Hint it doesn’t like periods 🙂
  6. Click Create.
  7. It will take you to another page, click “Continue”.
  8. Now everything is basically setup, it will take us to a page that looks like what is below, just click the “Deploy” button.
    python flask hello world app deploybutton
  9. Grab a cup of coffee or take a bathroom break, well a quick one! It will only take a minute or two to deploy the app.
  10. In a hot second you should be taken to a page that looks like what is below. To view your hello world app just click the button “View your App”.
    python flask deploy-done

Thats it for the quick and easy steps. Let’s go through the more advanced steps where you can modify the code and upload the app from your own machine.

A little more involved steps

  1. This will assume you have signed up for an account, steps 1 and 2 from above. If you haven’t signed up for an account scroll up and do that now.
  2. Install Git, follow the instructions from here.
  3. Install the Cloud Foundry command line. Choose the appropriate installer from here and download it and run the installer. You might be asking what Cloud Foundry is, its the open source Platform as a Service that Bluemix is built on.
  4. Open up the terminal/command prompt
    Mac – Click on the finder icon in the top right, search for terminal and open that
    Linux – Depends on your distro, but you probably know where it is, in the menu look for accessories usually then terminal, open that
    Windows – Click the start button, search for cmd, open that
  5. Type the following. The following commands downloads the starter app and puts us into the right directory to deploy the app.

    [code]git clone https://github.com/IBM-Bluemix/python-hello-world-flask.git
    cd python-hello-world-flask[/code]

  6. Next we need to login to Bluemix, we will use the terminal window that we already have open for this.

    [code]cf login -a https://api.ng.bluemix.net[/code]

    Note: It will ask for your username and password, this is the one you just created.

  7. Last step, we just need to upload the app, run the following replacing myappname with the URL you want your app to be available at. Bluemix will give you a URL based on this name. If I chose jeff-is-awesome, my app would be available at http://jeff-is-awesome.mybluemix.net.

    [code]cf push myappname[/code]

    If you get an error mentioning something like below, that means someone already has an app using that URL, just choose another one and rerun the command

    Error:

    [code][01:54 PM] jsloyer@Jeffs-MacBook-Pro [python-hello-world-flask]>cf push jeff-is-awesome
    Creating app jeff-is-awesome in org jbsloyer@us.ibm.com / space demos as jbsloyer@us.ibm.com…
    OK

    Creating route jeff-is-awesome.mybluemix.net…
    FAILED
    Server error, status code: 400, error code: 210003, message: The host is taken: jeff-is-awesome[/code]

    Fix:

    [code]cf push myappname-unique[/code]

    You will basically get some output that looks like the following. It will give you the URL to access your app. In this case the URL to my app is http://jeff-is-awesome2.mybluemix.net.

    [code][02:05 PM] jsloyer@Jeffs-MacBook-Pro [python-hello-world-flask]>cf push jeff-is-awesome2
    Updating app jeff-is-awesome2 in org jbsloyer@us.ibm.com / space demos as jbsloyer@us.ibm.com…

    … snip …

    App jeff-is-awesome2 was started using this command `python hello.py`

    Showing health and status for app jeff-is-awesome2 in org jbsloyer@us.ibm.com / space demos as jbsloyer@us.ibm.com…[/code]

Wrapping Up

To recap we just went through two different ways to deploy a python app to Bluemix. The first method is really quick so you can see the power of the platform and get something up and running quick. The second approach used the command line so you can modify the app and hack on it and customize it.

Sign up for Bluemix. It’s free!

Feedback

Follow us on Twitter at @IBMBluemix.

Follow the author of this blog post (Jeff Sloyer, one of our developer advocates) at @jsloyer

IBM Cloud Kubernetes Service - Core Dev Lead

More stories
November 2, 2018

Manage and Test Your Chatbot from the Command Line

With Watson Assistant, you can build chatbots—solutions that understand natural language and respond to the user input. In order to not just return hard-coded answers, it is pretty common to integrate database systems and other services into the solution.

Continue reading

October 30, 2018

Deploying a React Web App with IBM Cloud Kubernetes Service

The IBM NodeJS team has built a starter for developers to quickly create and deploy a MERN stack in a Kubernetes container. MERN stands for MongoDB, Express, React and NodeJS. Our MERN starter is a working application with a React front-end that makes HTTP requests to an Express/Node.js back-end, where sessions are persisted using MongoDB.

Continue reading

October 10, 2018

Growth Fabric – Learnings for Repeatable Growth

If mastering growth isn't already challenging enough, how do we ensure it's repeatable? We've got five steps to ensure that your robust efforts to create or transform yourself and your organization into a growth juggernaut are not lost the moment that something changes.

Continue reading