Home

Tags

Шаблон wsgi + bottle + mysql

2010-04-16 bottle mysql

index.wsgi

# coding: utf-8

import sys
import os

g_basePath = os.path.dirname(__file__)
sys.path.append(g_basePath)
os.chdir(g_basePath)

from main import *
import bottle
#bottle_last.debug(True)
application = bottle.default_app()

main.py
# coding: utf8

import MySQLdb
from bottle import route

db=MySQLdb.connect("localhost","user","pasw","dbname")

@route('/')
def main():
    cursor = db.cursor()
    cursor.execute('SELECT * FROM data LIMIT %s', (10,) )
    res = cursor.fetchall()
    if res: msg = str( res )
    else: msg = 'none result'

    return msg



подключение к Apche через wsgi