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
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- How to Convert MySQL Data to JSON using PHP
- Custom Authentication Login And Registration Using Laravel 8
- Slick Slider Basic With Example
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- How to change date format in PHP?
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- Image Lazy loading Using Slick Slider
- Calculate Subtotal On Quantity Increment in Woocommerce Single Product Page
- Slick Slider Multiple Items With Example
Total Views: 247
Share