I started to create in Django sample project, first command:
django-admin.py startproject test
gives me:
- root
- test
- __init__.py
- settings.py
- urls.py
- wsgi.py
- manage.py
Now I create first app:
python manage.py startapp foo
it created for me folder root/foo
so how I should understand my root/test
folder. Is this folder for global config of my project and nothing more? (similar to Symfony 2 app folder)
I am confused because Django docs tells:
The inner mysite/ directory is the actual Python package for your project
but manage.py startapp foo
create app under root, not under root/test
(mysite equivalent)
[EDIT]
Two commands:
python manage.py startapp app
and:
django-admin.py startapp app
gives me app inside project root, not under root/name_of_generated_project
Django 1.4
[EDIT] 2
Sorry guys, my fault, now is everything ok.
[EDIT] 3
I want to create another project again:
django-admin.py startproject jobeet
my initial structure is similar to above.
Now I want to try create app (inside jobeet folder):
django-admin.py startapp jobs
and I end up with jobeet/jobs
not jobeet/jobeet/jobs
again :/
so inside my project root I have:
- jobeet
- jobs
- manage.py
another command:
python manage.py startapp app
gives me the same result
So let's say you create a new Django project testproject
:
django-admin.py startproject testproject
This creates a new project with the following minimal set of files:
testproject/
├── __init__.py
├── manage.py
├── settings.py
└── urls.py
To create a new app for your first site mysite1
go into testproject
directory and run:
python manage.py startapp mysite1
which results in a new directory mysite1
for the mysite1
app.
I.e. with just these two commands you would arrive at this hierarchy:
testproject/
├── __init__.py
├── manage.py
├── mysite1
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── settings.py
└── urls.py
Refer to the django-admin.py
and/or manage.py
individual commands here.
In Django there is a one-to-many relationship between a project
and an app
. An app is usually one individual site component (e.g. comments
, ratings
), whereas a project is an organisation of several apps and can power many different sites. That's why you get the sites framework. In practice, one project usually serves one website, but with Django sites
app with one project you can serve as many websites as you like, for reusability's sake.
P.S. I think creating a project simply called test
is not a good practice because with Django unit tests at app
level unit tests will go into a file called tests.py
or within a folder called tests
.
UPDATE for Django 1.4
As @zeantsoi has commented below, my answer:
applies to Django 1.3 and prior. Per the docs, beginning in 1.4, base configuration files (including settings.py, urls.py, and wsgi.py) are abstracted into a subdirectory titled the same name as the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With