Django目录结构?

时间:2012-06-26 22:28:54

标签: django

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

目前的结构是:

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

[edit]我想问一下我在上面的direcotry结构中创建的队列服务代码的放置位置。我应该创建一个新目录吗?

2 个答案:

答案 0 :(得分:61)

常见结构

在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

答案 1 :(得分:1)

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