0

在 django 1.6 中,我有一个用于对数据库进行分析的命令,具有一组功能。

├── management
│   ├── __init__.py
│   └── commands
│       ├── __init__.py
│       ├── analysis.py

我喜欢将 analysis.py 分解为一组文件(可能是一个模块......)。用于 django 命令的模块的正确目录结构是什么?

也许像这样......?

├── management
│   ├── __init__.py
│   ├── analysis_module
│   └── commands
│       ├── __init__.py
│       ├── analysis.py

和测试,测试analysis_module的正确 ubication 是analysis_module什么?

4

1 回答 1

0

一个选项,将代码模块从 django 项目中取出

├── analysis_module
├── test
├── django_project
│   ├── app
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── management
│   │   │   ├── __init__.py
│   │   │   └── commands
│   │   │       ├── __init__.py
│   │   │       └── analysis.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.pyc
│   │   └── views.py
│   └── django_proyect
│       ├── __init__.py
│       ├── settings.py
│       ├── urls.py
│       └── wsgi.py

但为此,我需要将模块添加到sys.path可能的路径中manage.py

# manage.py
sys.path.append(os.path.abspath(__file__ + '/../../'))

并从分析命令导入

# analysis.py
import analysis_module

有了这个,我可以单独对 analysis_module 进行测试。

于 2014-04-24T12:25:01.887 回答