Liron Harel
Liron Harel

Reputation: 11247

Running Python scripts on local machine

I am trying to run a simple hello world example in python that runs against mongodb. I've set up mongo, bottle and pymong and have the following script inside C:\Python27\Scripts:

import bottle
import pymongo


@bottle.route('/')
def index()
    from pymongo import Connection
    connection = Connection('localhost', 27017)

    db = connection.test

    names = db.names

    item = names.find_one()

    return '<b>Hello %s!</b>' % item['name']

bottle.run(host='localhost', port=8082)

-!-- hello.py   All L8  (Python)

I want to run this locally and I go to http://localhost:8082 but I get not found not found. How can I run that code to test it locally on my computer so I can test the code via the browser. I am running Windows 7 and have WAMP installed.

Upvotes: 0

Views: 1286

Answers (2)

Messa
Messa

Reputation: 25191

This script will run standalone (bottle.run() starts its own Python webserver), so you do not need any WAMP - just run this script. Run it from command line so you see if there are any errors.

You also need to have running MongoDB to connect to it. You can run it from command line too if you do not have MongoDB configured to start automatically after Windows start.

Upvotes: 1

jsalonen
jsalonen

Reputation: 30491

1) Add : after function name:

def index():

2) WAMP does not include MongoDB. You need to install Mongodb locally as well.

3) If something doesn't work, then you generally should be looking console for errors.

Upvotes: 1

Related Questions