Skip to main content

Get started with Python Flask Framework on IBM Bluemix

Get started with Python Flask Framework on IBM Bluemix

The tutorial will develop a Python web application based on Flask framework and deploy the app on IBM Bluemix. The app shows up a basic form which users can type their names. When hit enter the name will be added to database and can be accessed at http://base_url/api/visitors

1. Requirement

2. Clone example code and run locally

git clone https://github.com/IBM-Bluemix/get-started-python
cd get-started-python

  • Rename your app
Open up,manifest.yml similar like:
    applications:
        - name: Lecheebot
        random-route: true
        memory: 128M
now, you can run your app locally by typing the command:
pip install -r requirements.txt
python hello.py
Your app is now accessible at http://localhost:8080

3. Deploy to IBM Bluemix using Cloud Foundry CLI

Ensure you have IBM Bluemix account and installed CF CLI on your machine. if not, follow the steps: [https://github.com/cloudfoundry/cli#downloads
  • Log in to CF CLI
Run CMD as administrator, then login to CF with the commands:
cf api https://api.ng.bluemix.net
cf login
Enter your email and password.
  • Deploy your app
Open CMD at your app reposit that you cloned in step 2. Execute the command to deploy your app:
cf push
You can view your app status by the command:
cf apps

4. Add Database

  • To connect to Cloudant NoSQL DB, follow these steps:
  • Navigate to your app. Click on "Connect new" button on Connections Group. Choose Cloudant NoSQL DB service on the categories. Finally, click Create button.
  • Ensure that you connect Cloudant NoSQL DB service to your application. If not, click on the "Connect existing" to connect with service.
Now, You can test your app at your app URL.
  • To connect Database for working locally:
  • Create a file with the name vcap-local.json
  • Add the following detail:
{
 "services": {
   "cloudantNoSQLDB": [
     {
       "credentials": {
        "username": "<your_username>",
        "password": "<your_password>",
        "host": "your_host",
        "port": 443,
        "url": "yoururl"

       },
       "label": "cloudantNoSQLDB"
     }
   ]
 }
}
You can find the username, password, host by click on Cloudant NoSQL DB service at your IBM Blumix console. Then click on "Service Credentials". Copy and pass information to your vcap-local.json file.
Now you can test your app locally with the connected database.
python hello.py


Comments

  1. It was an excellent article to hear from you which is very useful. Thank you so much for gathering all this information on how to get started with Python Flask Framework on IBM Bluemix, it’s very clever and will be extremely helpful for all people.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Las Vegas casino - Dr.MCD
    Las Vegas is the most exciting casino in town, and is it 밀양 출장샵 located? 여주 출장마사지 · The 속초 출장마사지 best 의정부 출장샵 casinos for slots in Vegas are at · 안동 출장안마 Play Las Vegas' two best casinos: The

    ReplyDelete
  4. genuinely a gainful article for us. Keep posting, Thank you. Small size power module suppliers

    ReplyDelete
  5. Nice article. This has a lot of information. Thank you. . Oracle Fusion HCM Training

    ReplyDelete

Post a Comment

Popular posts from this blog

Localization of Dates and Times with Flask-Moment

My latest publication: Environment monitoring system for agricultural application based on wireless sensor network

OpenHab2 - MQTT binding demo