23

我想实现一个特定于项目的简单排队服务。代码应该放在 Django 目录结构中的什么位置?

目前的结构是:

sound/
    __init__.py
    models.py
    tests.py
    views.py
    static

[编辑] 我在问将我在上面的目录结构中创建的队列服务代码放在哪里。我应该创建一个新目录吗?

4

2 回答 2

62

常见结构

在 Django 1.4+

project_root/
   project_name/
       media/
       static/
           some_app/css/app.css  # overriding an app css file from project level
           css/
               project.css
       static_root/  # in production using the collectstatic command
       templates/some_app/foo.html  # overriding some_app at project level
                /admin/some_app/some_model/change_list.html
                # overriding admin changelist for some_app.models.some_model
       settings/
           __init__.py
           base.py    # settings common to all instances of the project
           dev.py
           staging.py
           test.py
           prod.py
       urls.py
   some_app/
       static/
           css/
               app.css
       templates/some_app/foo.html
       urls.py
       views.py
       models.py
   manage.py

在 Django 1.3 及之前版本中

project_root/
   some_app/
       templates/some_app/foo.html
       static/
           css/
               app.css
       urls.py
       views.py
       models.py
   media/
   static/
       some_app/
           css/
               app.css  # overriding an app css file from project level
       css/
           project.css
   static_root/ (in production)
   templates/some_app/foo.html # overriding some_app at project level
            /admin/some_app/some_model/change_list.html
            # overriding admin changelist for some_app.models.some_model
   settings/
       __init__.py
       base.py    # settings common to all instances of the project
       dev.py
       staging.py
       test.py
       prod.py
   urls.py
   manage.py

替代方法

project_root/
    .gitignore
    README.md
    docs/
    venv/
    src/
       main/
           media/
           static/
               some_app/css/app.css  # overriding an app css file from project level
               css/
                   project.css
           static_root/  # in production using the collectstatic command
           templates/some_app/foo.html  # overriding some_app at project level
                    /admin/some_app/some_model/change_list.html
                    # overriding admin changelist for some_app.models.some_model
           settings/
               __init__.py
               base.py
               dev.py
               staging.py
               test.py
               prod.py
           urls.py
       some_app/
           static/
               css/
                   app.css
           templates/some_app/foo.html
           urls.py
           views.py
           models.py
       manage.py
       wsgi.py
于 2012-06-27T08:55:11.793 回答
1

如果你需要使用数据库,你应该将数据模型添加到models.py。对于您的程序,我建议将其写入新的 python 文件(例如queuing.py)中,您可以在想要使用它的时间和地点导入这些文件。您也可以为此创建另一个 django 应用程序。

于 2012-06-26T23:49:56.710 回答