简体   繁体   中英

Is there any way to automatically set Debug True Django application

I have a Django API that is being deployed in PythonAnywhere. For that, I can not let the default option in settings.py as True :

DEBUG=True

However, the app also has a Swagger page using drf-yasg library. For that to work locally, I have to set the debug option as true.

However is being troublesome to maintain it, and I often mistakenly commit it as True to the repository.

Is there anyway I could manage this option so whenever I am running locally, it will automatically set it to True , but leave it as False by default?

DEBUG=False

For this purpose I use python-decouple package. To distinguish between production and development environments you can create one .env file with all production-related variables in it. In settings.py when retrieving the configuration parameters leave every default option with the one used in development. So when .env file is not present the default values are gonna be set.

from decouple import config

DEBUG = config('YOUR_ENV_VAR_DEBUG', default=True, cast=bool)

For more real-world use cases, please refer to the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM