1

django-admin startproject mysite creates something like this:

/mysite
    /mysite
        settings.py
        ....

I know if I add a period at the end of command (django-admin startproject mysite .) the second folder will not be created, but I don't understand what is the rationale behind creating nested project folders. Maybe I'm missing something critical?

Omid Shojaee
  • 333
  • 1
  • 4
  • 20

2 Answers2

3

A project is a collection of one or more apps. When you create a project by default, a default app of the same name is made within a folder of the same name. Thus you end up with a nested folder structure like /myproject/myproject.

I suppose why it doesn't dump all the default/root app files in the root of the project folder is because that would make it a bit more complex to manage multiple apps. The default app is structurally the same as other apps. Django relies on certain conventions, including special filenames and certain folder structure, to tell what's what.

In a structure like this:

myproject
  /myproject
  /myapp
  /anotherapp

You can refer to myapp from within myproject, and Django can locate myproject very cheaply due to these folder conventions (and likewise the other way around).

You can tell which app is the default app by examining manage.py, which will have a line like this within def main() os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

evan g
  • 44
  • 6
0

The command django-admin startproject mysite creates a project. Django defines a project as a container for one or more apps. The command creates a project and an app.

If am correct you are attempting to create an app inside another app. One may decide to nest an app due to various reasons such as close association or dependencies of apps

Eg. a website may have a public site and an administrator site. The public site(app) may have public account user(another app) implemented as a user model. The administrator site may have private account user. Therefore one may seek to contain public user model inside the public site and the same for private user account.

Fix

The command django-admin startproject mysite . is the wrong command to use. You don't nest projects, you nest apps. To create an app use python manage.py startapp mysite, then cd into the app then use python manage.py startapp nestedsite to nest it.

See [https://stackoverflow.com/q/2862084/6753642][1]

mello
  • 21
  • 2
  • 5
  • Thanks. I don't want to nest projects or apps. I'm asking why Django creates an extra ```mysite``` folder if I don't put a dot (.) at the end of command. – Omid Shojaee Jun 28 '21 at 16:58