Sometimes, we want to import from config file in Python Flask.
In this article, we’ll look at how to import from config file in Python Flask.
How to import from config file in Python Flask?
To import from config file in Python Flask, we can use the config.from_object
method.
For instance, we write
class Config(object):
DEBUG = True
DEVELOPMENT = True
SECRET_KEY = "secret"
FLASK_HTPASSWD_PATH = "/secret/.htpasswd"
FLASK_SECRET = SECRET_KEY
DB_HOST = "database"
class ProductionConfig(Config):
DEVELOPMENT = False
DEBUG = False
DB_HOST = "my.production.database"
to create config classes in the config.py file.
Then we write
app.config.from_object("config.ProductionConfig")
in app.py to load the config from the ProductionConfig
class in the config.py file with the app.config.from_object
.
app
is the Flask
app instance.
Conclusion
To import from config file in Python Flask, we can use the config.from_object
method.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Custom Authentication Login And Registration Using Laravel 8
- How to Convert MySQL Data to JSON using PHP
- Google Login or Sign In with Angular Application
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example
Total Views: 862