[英]putting python variables into cleardb
簡而言之
我有一個heroku python設置程序,並設置了cleardb數據庫,但不知道如何將python變量放入該數據庫中。 在python中,哪些代碼行連接到我的數據庫,並將一些變量添加到數據庫中。 或哪里有python-heroku-cleardb插入代碼的一些示例代碼。
在長
我有一個python heroku設置,並按照這里的描述設置了cleardb: https ://devcenter.heroku.com/articles/cleardb
但是我在查找有關如何例如將python變量放入我的數據庫中的代碼時遇到了麻煩。 我也很難找到有關如何在heroku / cleardb框架內構建mysql dtabase的任何資源。
他們提供了可放入我的settings.py文件的代碼,但我沒有。 我有一個主應用程序文件:
...
class ToDatabase(tornado.web.RequestHandler):
def post(self):
data_json = self.request.arguments
print(data_json)
...
class Application(tornado.web.Application):
def __init__(self, port=PORT):
tornado.web.Application.__init__(self, debug=True)
self.logger = logging.getLogger()
self.ioloop = tornado.ioloop.IOLoop.instance()
self.port = port
self.address = 'www.examplesite.com'
self.add_handlers('', [
(r'/', IndexHandler),
(r"/todatabase/",ToDatabase),
和data_json具有我想要在數據庫中的一些值。
注意:我有使用MySQL-python和MySQL以及構建數據庫的經驗,但是在heroku中如何使用它卻一無所獲。
這個問題確實是錯誤的問題。
heroku config
在DATABASE_URL輸出中輸出遠程cleardb數據庫的主機,數據庫名稱,用戶和密碼。
在db = MySQLdb.connect(host="...", user = "...", passwd="...", db = "...")
行中使用此信息進行連接。 然后,只需使用基本的MySQLdb代碼插入即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.