如何将变量从settings.py传递给视图? [英] How to pass a variable from settings.py to a view?
本文介绍了如何将变量从settings.py传递给视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的Django应用程序中使用以下设置获取项目路径:
I'm getting the project path in my Django app in settings.py using:
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
我想在其他文件中使用PROJECT_PATH值视图,例如用于定位到静态路径中文件的路径。
I would like to use the PROJECT_PATH value in other views, such as for locating the path to files in my static path. How can I make this into an accessible variable?
推荐答案
从django.conf导入设置使用 code>但请注意,
设置
不是一个模块。 文档清楚地解释了你的用例。
Use from django.conf import settings
but mind that settings
is not a module. The documentation clearly explains that and your use case.
这篇关于如何将变量从settings.py传递给视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文