[Django]-Django, can't create app in subfolder

2👍

I had the same trouble on my Mac as well.
I did solve it upgrading Django from vervion 1.3 to version 1.4.

37👍

Try this:

mkdir Apps\newapp
python manage.py startapp NewApp Apps/newapp

And you will to create a app called “NewApp” inside folder “Apps/newapp”.

17👍

Create your Apps directory from your project’s root directory-

mkdir Apps

Move to your Apps directory-

cd Apps

Run python by calling the manage.py in your root project directory-

python ../manage.py startapp newapp

There you go

10👍

from the docs:

If the optional destination is provided, Django will use that existing directory rather than creating a new one. You can use ‘.’ to denote the current working directory.
django-admin.py startapp myapp /Users/jezdez/Code/myapp

So try python manage.py startapp myApp ./Apps/myApp or with the full path.

3👍

Manage.py file is a thin wrapper of django-admin.py

In case, you want to create a new app in any directory

Try this:

$ cd <directory path>
$ django-admin.py startapp <app-anme>

3👍

For django 3.2.9

Create a sub directory Apps to hold all the apps, move into it, create a directory for the app myApp, then come back to root directory

mkdir Apps && cd Apps && mkdir myApp && cd ..

add a __init__.py file (is a python way to treat a directory as a package)

Create a myApp inside Apps sub directory

manage.py startapp myApp Apps/myApp

(in windows, please use backslash)
above two lines of code will create myApp

Now, in settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Local
    'Apps.myApp.apps.MyAppConfig', # new
]

in ./Apps/myApp/apps.py file, change name='myApp' to name='Apps.myApp' will solve the issue

1👍

As the documentation says you can use the command

django-admin startapp name [directory]

but in the example

django-admin startapp myapp /Users/jezdez/myapp

the documentation does not say that python creates the myapp folder. You should do it before the startapp command.

0👍

For newer versions of Django

1. Create the required folder structure

mkdir -p apps/myapp && touch apps/__init__.py

2. Create the app

python manage.py startapp myapp apps/myapp

3. Configure the apps/myapp/apps.py file as follows:

from django.apps import AppConfig


class MyappConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.myapp'

4. Append the app in the INSTALLED_APPS list at [project]/settings.py

INSTALLED_APPS = [
    ...
    'apps.myapp',
]

Tested on Django 4.2.3 🤖

Leave a comment