首页 > 解决方案 > 从一个项目到另一个项目访问 python 脚本

问题描述

Main folder
   |-project1
   |-project2 

我有 django 项目的上述结构。当我在脚本中的 project1 中使用 os.chdir(to_project2) 到项目 2 时,我想访问 project2 的 settings.py 并获取一些属性。可能吗?

标签: djangopython-2.7

解决方案


#You need to point your directory.[Ex: project2]
import os 
os.chdir(project2 )
cd = os.getcwd() 

# print the current directory 
print("Current directory:", cwd)

#For Access the Django setting attributes
import django
from django.conf import settings

您可以从您的一个 python 文件中使用所有上述代码:something.py


推荐阅读