[PYTHON] Prevent unnecessary directories from being created under the current directory when you start project with Django

Introduction

When I do a start project with Django, a directory is wasted under the current directory. .. .. Isn't that the case?

When I often start building new apps in Django, I first create a directory, go to it, and then startproject.

#Create a mysite directory on Desktop and start a project in it
$ cd ~/Desktop
$ mkdir mysite 
$ cd mysite
$ django-adimin startproject mysite

However, if you start the project in this way, the directory will be created in vain like this.

#Mysite is wasted again in the mysite directory
mysite/
└── mysite
    ├── mysite
    │   ├── __init__.py
    │   ├── asgi.py
    │   ├── settings.py
    │   ├── urls.py
    │   └── wsgi.py
    └── manage.py

Why is this happening in the first place? And how can we avoid such wasteful things?

Anyway, I read the formula

Read the official page of Django's start project. I translated the following English document by myself. Django/startproject


django-admin startproject name [directory] (This command) creates a directory structure for the project for the given project name in the current directory or in the specified location. By default, the new directory contains manage.py and the project's packages (including setting.py and other files). ** If only the project name (for example, the project name mysite) is given **, both the project directory and the project package will be named mysite, which is the same as the project name, ** the project directory will be in the current working directory. Will be made. ** ** If a storage location is specified, Django will use the directory that exists as your project's directory. Then create manage.py and a project package in it. Dots indicate the current working directory.


~~ Combined with my childish Japanese translation ~~ I'm talking about what to say, so I'll add a little more.

First, django-admin startproject name [directory] will create a directory structure by specifying the project name with name and the location to start the project with directory.

The directory structure is basically the manage.py and mysite directories shown in the code tree. The mysite directory is the project package.

By the way, the formula also politely tells me what happens if I do not specify the [directory] of the save destination here. The project directory is created in the current working directory (the directory you are in), and then manage.py and the project package are created in it. A useless directory was unintentionally created here.

solution

The solution is simple, you can take one of the following two.

――Stop making a directory from the beginning and starting project in it --Declare that it will be created in the current directory with dots like django-admin startproject name.

That's all for today.

environment

MacOS Python 3.7.5 Django 3.0.3

Recommended Posts

Prevent unnecessary directories from being created under the current directory when you start project with Django
Things to do when you start developing with Django
A solution when you can't start project Django on Windows
A story when a directory is buggy with the django-admin start project command in a virtual environment using Pipenv
List all files under the current directory line by line with full path
Start the web server in the current directory
Search for files with line feed code CR + LF under the current directory