librelist archives

« back to archive

Flask with MongoDB

Flask with MongoDB

From:
Yaroslav Kyrpych
Date:
2014-09-04 @ 03:56
Hello!

I am new to Flask and web development. I am working on application that
uses MongoDB (pymongo). I am trying to set up config file. So far it looks
as follows:

import os
class Config(object):
 DEBUG = False
 TESTING = False
 CSRF_ENABLED = True
 SECRET_KEY = 'TBU'
 CSRF_SECRET_KEY=TBU'
 THREADS_PER_PAGE=2

class ProductionConfig(Config):
    DEBUG = False

class StagingConfig(Config):
    DEVELOPMENT = True
    DEBUG = True

class DevelopmentConfig(Config):
    DEVELOPMENT = True
    DEBUG = True

class TestingConfig(Config):
    TESTING = True

I am bit unclear how I set path to a folder where mongodb saves data.
Please note I have several databases that I are located in the same folder
(data), so I plan to make calls to specific database in a specific function
for each page, I just want to import path to a folder with databases. My
folder tree looks as follows now:

C:\app\data - here all mongodb databases are located, i.e. data for
application.
C:\app\__init__.py
C:\app\config.py
C:\app\virtualenv.py
C:\app\flask
C:\app\static
C:\app\templates
C:\app\source_data
C:\app\__pycache__

__init__ file looks as follows:
app=Flask(__name__)
app.config.from_object(__name__)

Another question is how do I specify which mode (development, production,
etc) to use.


Any help is much appreciated.

Thank you,

Yaroslav