django specific settings app

给你一囗甜甜゛ 提交于 2019-12-08 16:43:52

问题


I am working on a django app that needs a directory to download and store files.

I want to keep my app reusable so I do not want to hard code the path of this directory. So I want to make this path a setting/a global variable that can be set up.

Where could I put this setting/global variable?

Is this kind of approach good ? http://blog.muhuk.com/2010/01/26/developing-reusable-django-apps-app-settings.html

Thanks for your advice!


回答1:


I use the following methodology:

# some file in your app:

from django.conf import settings

MY_APP_SETTING = getattr(settings, 'MY_APP_SETTING', 'some default value')

This effectively allows end-users to customized the setting in their own settings.py, but still ensures that there's always some default value set. You can now use MY_APP_SETTING at will in the rest of your code.

UPDATE

The link in your question was taking too long to load, so I just went ahead and answered. As it turns out, the method I suggested is the same as what it suggests, so yes, I'd consider that approach good ;).



来源:https://stackoverflow.com/questions/9446897/django-specific-settings-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!