django - 从一个项目到另一个项目访问 python 脚本
问题描述
Main folder
|-project1
|-project2
我有 django 项目的上述结构。当我在脚本中的 project1 中使用 os.chdir(to_project2) 到项目 2 时,我想访问 project2 的 settings.py 并获取一些属性。可能吗?
解决方案
#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
推荐阅读
- android - 如何检测前置摄像头是否在android中可用?
- php - 根据 Woocommerce 中的运输类别有条件地设置运输成本
- xcode - 在 Mac 上启动 Jenkins 本地服务器
- angular - 如何使用 Ngrx 获取商店价值
- swift - Swift - 打印一年中的当前周是什么
- laravel - Laravel:如何在不使用或定义路由的情况下将控制器连接到视图
- node.js - Socket.io 如何在本地服务器上创建文件运行时间
- python - python制作相关矩阵
- php - 如何在php中制作动态照片查看器?
- testing - 当我通过 selenium 运行我的测试脚本时,如果屏幕锁定我的测试用例失败