我可以在Heroku中托管我的Python代码,而不是像Flask,Django这样的Web应用程序吗?

xjreopfe  于 9个月前  发布在  Python
关注(0)|答案(1)|浏览(72)

我的问题:HEROKU托管的应用程序不运行weather.py(简单代码),而不是flask或django
亲爱的,我是Loc,我只是Python新手
我的问题:HEROK中托管的应用程序无法运行
weather.py (简单代码),而不是flask或django。应用程序不会响应任何http请求
我已经准备了Profile Worker:pythonweather.py
requirements.txt
我成功地将源代码推送到Heroku,但python文件没有像我预期的那样工作
我想知道Heroku是否可以托管应用程序或仅托管Web应用程序。我真的需要你们的建议
谢谢

k10s72fa

k10s72fa1#

您已经在Heroku中设置了MONGODB_URI环境变量来指向MongoHQ数据库。将代码添加到Flask应用的顶部:

import pymongo
from flask import Flask

app = Flask(__name__)

# Get the MongoHQ database connection string
mongo_uri = os.environ.get('MONGODB_URI')

# Connect to the MongoHQ database
client = pymongo.MongoClient(mongo_uri)

# Store the database connection in the Flask app's context
app.context_processor(lambda: {'db': client.test})

# In your tweet consuming app, replace the code
 self.db = pymongo.MongoClient().test
#To
self.db = app.context['db']
# it will ensure that your app is using the same database connection as the Flask app.

相关问题