Django startproject fails after I manually created the project files/folders (name conflict?)

I’m setting up a Django + Channels project and I think I messed up the order.

I ran these commands:

cd ~
mkdir social_mvp
cd social_mvp

mkdir socialsite
mkdir core
mkdir -p core/templates/core
mkdir -p core/static/core/css

touch manage.py requirements.txt
touch socialsite/__init__.py socialsite/settings.py socialsite/urls.py socialsite/wsgi.py socialsite/asgi.py

python3 -m venv venv
source venv/bin/activate
pip install django channels

django-admin startproject socialsite .

error;

when I run `django-admin startproject socialsite . I get a error;

$ django-admin startproject socialsite .
CommandError: 'socialsite' conflicts with the name of an existing file or directory.

I get a CommandError saying it can’t create the project because something already exists / conflicts (it mentions socialsite and/or manage.py already existing). That makes sense because earlier I manually created manage.py and also created the socialsite/ folder + settings.py, urls.py, etc.

What’s the correct way to do this? Should I not manually create manage.py and the socialsite/ folder first? What’s the right command order for Django + Channels?

$ mkdir socialsite
$ touch manage.py requirements.txt
$ touch \
    socialsite/__init__.py \
    socialsite/settings.py \
    socialsite/urls.py \
    socialsite/wsgi.py \
    socialsite/asgi.py

You don't need to create the hierarchy of socialsite yourself, as django-admin startproject socialsite . should take care of these.

You should never create the project folders and files manually. The "django-admin startproject socialsite ." command will auto-create the project hierarchy and all the files, and that's the best practice. Also, don't create the requirements file as well, just run this command "pip freeze > requirements.txt", it will auto create the requirements file and saved the requirement.

The correct flow will be like this:

cd ~ 
mkdir social_mvp 
cd social_mvp 

python3 -m venv venv 
source venv/bin/activate 
pip install django channels 
pip freeze > requirements.txt

django-admin startproject socialsite . 
python manage.py startapp core

This is the best practice for creating Django projects.

Вернуться на верх