烧瓶mongoengine通过uri连接 [英] flask mongoengine connect through uri
本文介绍了烧瓶mongoengine通过uri连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小烧瓶应用程序,正在将其部署到heroku.
Hi I have a small flask application which I am deploying to heroku.
我的本地配置如下:
My local configuration looks like this:
from flask import Flask
from flask.ext.mongoengine import MongoEngine
app = Flask(__name__)
app.debug = True
app.config["MONGODB_SETTINGS"] = {'DB': "my_app"}
app.config["SECRET_KEY"] = "secretpassword"
db = MongoEngine(app)
所以,我知道我需要配置该应用程序以使用mongo URI
连接方法,并且我拥有连接信息:
So, I know that I need to configure the app to use the mongo URI
method of connection, and I have my connection info:
mongodb://<user>:<password>@alex.mongohq.com:10043/app12345678
对于修改我的应用程序以通过 URI
进行连接的语法,我有些困惑.
I am just a little stuck as to the syntax for modifying my app to connect through the URI
.
任何帮助将不胜感激.
推荐答案
所以我终于开始工作了:
So I got it working (finally):
from flask import Flask
from mongoengine import connect
app = Flask(__name__)
app.config["MONGODB_DB"] = 'app12345678'
connect(
'app12345678',
username='heroku',
password='a614e68b445d0d9d1c375740781073b4',
host='mongodb://<user>:<password>@alex.mongohq.com:10043/app12345678',
port=10043
)
尽管我预计其他各种配置也会起作用.
Though I anticipate that various other configurations will work.
这篇关于烧瓶mongoengine通过uri连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文