How to create all django apps inside a folder?

Question:

Here is my project folder structure:

.venv [virtual environment]
apps
budgetApp
    __init__.py
    settings.py
    urls.py
    wsgi.py
manage.py

When I run the following command python manage.py startapp budget it creates a new folder named budget beside the folder budgetApp.

But I want to create all my apps folder inside the apps folder.

Asked By: Kishor Sterling

||

Answers:

You can specify the path to destination directory after app_label in the startapp command.

python manage.py startapp <app_label> [destination]

In your case you the command is like this:

python manage.py startapp budget ./apps

Then you should add just created app name in settings.py like below:

INSTALLED_APPS = [
    ...,
    'apps.budget',
]
Answered By: mrzrm
  1. At first, you need to create a directory Your_App_Name inside the /apps folder.
  2. After that, run the following command to create the new app
python manage.py startapp Your_App_Name ./apps/Your_Apps_Folder_Name/

Then don’t forget to add just created app name in the settings.py like below:

INSTALLED_APPS = [
    ...,
    'apps.Your_App_Name',
]
Answered By: Fatema Tuz Zuhora

First run python manage.py startapp budget app/budget

Then, on your settings.py, change the INSTALLED_APPS to the full path name:

INSTALLED_APPS = [
'app.budget.apps.BudgetConfig',
]
Answered By: Lord Elrond

You can also do it like this

cd apps && django-admin startapp app_name
Answered By: Koushik Das

When you use a nested structure for apps, you also need to change the name of the app in apps.py as follows:

class BudgetConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.budget'

Check https://code.djangoproject.com/ticket/24801 for more information.

Answered By: Mehdi Zare

If you’re on Windows, you’ll first need to create a folder app/budget. Then add the file __init__.py to the folder add. Then run the command py manage.py startapp budget app/budget.
Then, on your settings.py, change the INSTALLED_APPS to the full path

name:`INSTALLED_APPS = [
    ...,
    'app.budget',
]`

also need to change the name of the app in apps.py as follows

class BudgetConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'app.budget'
Answered By: Aleksei Kravchenko

I am making the following assumptions:

  1. You are on a Unix/Linux PC
  2. Your app is named: perstep
1. mkdir -p apps/perstep && touch apps/__init__.py
2. python manage.py startapp perstep ./apps/perstep

OR

1. mkdir -p apps && touch apps/__init__.py
2. cd apps && django-admin startapp perstep

configurations

reference the added diagram when in doubt.

1. In settings.py "INSTALLED_APPS" add "apps.perstep.apps.PerstepConfig" to it.

├── apps
│   ├── __init__.py
│   └── perstep
│       ├── apps.py

2. Change name = 'apps.perstep' within 'apps > perstep > apps.py' PerstepConfig

This works as at Django==4.0.5

Answered By: iChux
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.