S
S
Sergey Eremin2018-11-29 16:23:54
Django
Sergey Eremin, 2018-11-29 16:23:54

How to move the root of a Django project to a subdirectory inside a PyCharm project?

When you create a pure Django project in PyCharm, it creates all the necessary folders with files (similar to django-admin startproject django_prj) and makes settings inside the PyCharm project (how and where to run manager.py, for example). This creates a directory structure in the PyCharm project folder:

PROJECT
├───.idea
├───.git
├───prj
├───app
├───templates
└─manage.py

Those. the root of the PyCharm project is the same as the root of the Django project. But I need the Django project to live in a subdirectory. Those. something like this structure:
PROJECT
├───.idea
├───.git
├───django_prj
│         ├───prj
│         ├───app
│         ├───templates
│         └─manage.py
└─другие_файлы

But that doesn't work. Dug in Pycharm's Run/Debug Configurator project settings:
  1. If you create a Django project with your hands, prepare its structure and then hook it into a PyCharm project, then the Run / Debug Configurator stubbornly tries to run PROJECT/django_prj/django_prj/settings.pyinstead PROJECT/django_prj/manage.pyof ... with obvious consequences. No Additional options or Custom run command can convince him to run what I need ( Custom run command - just adds everything that you write in it after the server start line; Additional options - adds everything that is written in it in the same line but before specifying the IP:PORT of the server
  2. If you create a Django project at the same time as a PyCharm project, and then move the Django files to a subdirectory, then PyCharm for some reason stops launching manage.pyand tries to launch django-admin.pyfrom the project's virtual environment. The Additional options and Custom run command settings behave in the same way as in the previous paragraph, to convince you to search and run exactly manage.py, and at the same time it doesn’t work where you need it.

What to do? Surely the same task! Not all projects are made in Python alone. And if I still have a bunch of external configs, programs, etc. in the project, is it not good to keep them inside the Django code?!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Eremin, 2018-11-29
@Sergei_Erjemin

Solution: In the project tree, right-click the django_prj folder and select mark directory as source root !

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question