Question:
Python code can be hosted in Heroku instead of web apps like Flask, Django

Problem:

App hosted in HEROKU doesn't run weather.py (simple code), not Flask or Django


Dear all, Im just new to python


My problem: App hosted in HEROK doesn't run


weather.py (simple code), not flask or Django. App will not respond for any http request


I already prepared Profile worker: python weather.py


requirements.txt


I pushed source code to Heroku successfully, but Python file didn't work as I had expected


I wonder if Heroku can host an app or only host web apps. I really need advice from you all


Thanks


Solution:

You have set the MONGODB_URI environment variable in Heroku to point to your MongoHQ database. Add the code to the top of your Flask app:


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.


Suggested blogs:

>Can not run phpstan under docker with memory lack error

>Attempt to read property "data_audit" on array laravel view loop foreach

>How to use start and limit on DataTables in Laravel for mobile API?

>Login to Laravel API- Laravel

>Make Xdebug stop at breakpoints in PhpStorm using Docker

>Creating a service in Laravel using app(FQCN)




Ritu Singh

Ritu Singh

Submit
0 Answers