Fantastico is configured using a plain settings file. This file is located in the root of fantastico framework or in the root folder of your project. Before we dig further into configuration options lets see a very simple settings file:
class BasicSettings(object):
@property
def installed_middleware(self):
return ["fantastico.middleware.request_middleware.RequestMiddleware",
"fantastico.middleware.routing_middleware.RoutingMiddleware"]
@property
def supported_languages(self):
return ["en_us"]
The above code sample represent the minimum required configuration for fantastico framework to run. The order in which middlewares are listed is the order in which they are executed when an http request is made.
Below you can find technical information about settings.
This is the core class that describes all available settings of fantastico framework. For convenience all options have default values that ensure minimum functionality of the framework. Below you can find an example of three possible configuration: Dev / Stage / Production.
As you can see, if you want to overwrite basic configuration you simply have to extend the class and set new values for the attributes you want to overwrite.
This property holds the configuration of database. It is recommended to have all environment configured the same. An exception can be done for host but the rest must remain the same. Below you can find an example of functional configuration:
config = {"drivername": "mysql+mysqlconnector",
"username": "fantastico",
"password": "12345",
"port": 3306,
"host": "localhost",
"database": "fantastico",
"additional_params": {"charset": "utf8"},
"show_sql": True}
As you can see, in your configuration you can influence many attributes used when configuring the driver / database. show_sql key tells orm engine from Fantastico to display all generated queries.
This property holds development server hostname. By default this is localhost.
This property holds development server port. By default this is 12000.
This property defines public location of Fantastico documentation.
Property that holds all installed middlewares.
This property holds all routes loaders available.
Property that holds all supported languages by this fantastico instance.
Let’s imagine you want to create a custom dev configuration for your project. Below you can find the code for this:
class DevSettings(BasicSettings):
@property
def supported_languages(self):
return ["en_us", "ro_ro"]
The above configuration actually overwrites supported languages. This mean that only en_us is relevant for Dev environment. You can do the same for Stage, Prod or any other custom configuration.
For using a specific fantastico configuration you need to do two simple steps:
Set FANTASTICO_ACTIVE_CONFIG environment variable to the fully python qualified class name you want to use. E.g: fantastico.settings.BasicSettings
In your code, you can use the following snippet to access a specific setting:
from fantastico.settings import SettingsFacade
print(SettingsFacade().get("installed_middleware"))
If no active configuration is set in the fantastico.settings.BasicSettings will be used.
Method used to retrieve a setting value.
Parameters: |
|
---|---|
Returns: | The setting value. |
Return type: | object |
Method used to return the active configuration which is used by this facade.
Return type: | fantastico.settings.BasicSettings |
---|---|
Returns: | Active configuration currently used. |
Method used to return the root folder of the current fantastico project (detected starting from settings) profile used.