Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force django-admin startproject if project folder already exists

I want to start new django project in already existing folder and obviously get

CommandError: '/home/user/projectfolder' already exists. 

Is there some way to force startproject command to create project in an existing folder? I have some important data in that folder and also git folder so I don't want to move it somewhere and then move it back.

like image 424
valignatev Avatar asked Jul 15 '15 13:07

valignatev


People also ask

How do you run Django project which is already created?

Go to the directory where manage.py file of your Django project is present. It is normally the Base directory of your project. In that directory, Press Shift and Right Click at the same time. The from the Right Click Menu, Click on "Open PowerShell window here".

How do I fix Django admin not recognized?

'django-admin' is not recognized as an internal or external command, operable program or batch file. To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project.


2 Answers

Just use the current directory:

cd /home/user/projectfolder

django-admin.py startproject project .

The use of . just instructs Django to create a project in the current directory while:

django-admin.py startproject

instructs Django to create a project and create the necessary directory

If only the project name is given, both the project directory and project package will be named and the project directory will be created in the current working directory.

This fails because of the existing directory which is not a bug but a constrain in order to prevent accidents.

like image 67
petkostas Avatar answered Oct 08 '22 13:10

petkostas


You can make too like this:

 django-admin startproject name_project path_project 

Example:

 django-admin startproject example /tmp/example 
like image 45
Elinaldo Monteiro Avatar answered Oct 08 '22 14:10

Elinaldo Monteiro