23

I would like to implement a simple queueing service specific to a project. Where should the code go into in the Django directory structure?

Currently the structure is:

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

[edit] I am asking where to place the queue service code I created within the direcotry structure above. Should I create a new directory?

Cory
  • 14,865
  • 24
  • 57
  • 72
  • possible duplicate of http://stackoverflow.com/questions/2282034/web-application-django-typical-project-folder-structure – T I Jun 26 '12 at 22:43
  • Are you asking where to place this `sound` app folder? – jdi Jun 26 '12 at 23:46

2 Answers2

63

Common structures

In 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

In Django 1.3 and prior

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

Alternative approach

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
Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52
Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100
  • 1
    Where would you add templates? – starsinmypockets Dec 20 '12 at 20:44
  • 1
    @starsinmypockets per app you can add your default templates, probably without too much styling. At project level your override these, I have updated the example with templates. – Hedde van der Heide Dec 20 '12 at 21:25
  • why override templates at project level? – Eric Zheng Nov 12 '14 at 16:03
  • interesting because in the Django tutorial02, in order to override /admin/ templates, the custom `template` folder must be above the app, and above the project folder -- at the top-most level with `manage.py`. It seems counter-intuitive that it's not within the app (as it is a change we're applying specific to the app, no?) – Don Cheadle Feb 02 '15 at 21:09
1

If you need to use the database, you should add the data models to models.py. For your program I recommend writing it in new python files (e.g. queuing.py) that you would import when and where you want to use it. You could create another django app just for this as well.

Radek Simko
  • 15,886
  • 17
  • 69
  • 107
Dean Elbaz
  • 19
  • 1
  • 1
    _You could create another django app just for this as well._ That's not a good recommendation. The service code should be separated from MVC. In general, it's just not another app. – Radek Simko Feb 17 '14 at 07:24