22

I feel like I must be looking over something obvious because I am having trouble finding anything online about this. But basically here it is, I have a django Project, and I would like to store my apps inside of an apps folder, like thus...

myproject/
    client-side/
        media/
        static/
        templates/
    apps/
        app1/
        app2/
        etc. 
    __init__.py
    manage.py
    etc. (rest of root directory)

but have been unable to figure out how to >>>python manage.py startapp newapp and have it placed into the /apps/ folder. Is it ok to simply ok to startapp at the root level and manually move them into the /apps/ folder?

I greatly appreciate your thoughts and answers.

FYI running python 3.4.2 and Django 1.9.5 on Windows 10

2 Answers 2

41

You can specify the app's directory as a second parameter:

python manage.py startapp <app_name> <app_directory>

Note that no directory will be created, the app's files will be created directly in the specified directory. Example:

python manage.py startapp myapp apps/myapp

Will result in the given directory structure:

apps
└── myapp
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

Also note that the command won't create the directory for you.

Edit: as another (now deleted) answer pointed out, running the command from the apps directory would also work:

cd apps
python ../manage.py startapp myapp
6
  • 2
    This worked like a perfectly! Thank you aumo. Also have to mention an answer posted by @xyres (who deleted his comment for some reason) that running >>>python ../manage.py startapp newapp from the /apps/ folder worked as well.
    – Tarrant
    Jun 29, 2016 at 8:26
  • @Tarrant Yeah, I deleted that because this was the better answer as it makes use of Django's built-in feature.
    – xyres
    Jun 29, 2016 at 10:31
  • @xyres thank you for clarifying that the listed answer is the more appropriate answer - would not have known otherwise...Once again thank you aumo for pointing out a great answer.
    – Tarrant
    Jun 30, 2016 at 7:59
  • 2
    If I move the app into the apps folder, How can I register the app in the projects INSTALLED_APPS. cause each time I try to this, and the run server commands tells ImportError no module named apps.myapp.apps.Config???
    – user4985526
    Jul 25, 2017 at 3:08
  • 1
    If you are getting an ImportError, make sure you update your app name on apps.py file. In this example it should be name = 'apps.myapp' Dec 27, 2021 at 14:26
2

You can also use the django-admin command as well.

cd apps && django-admin startapp app_1

this will work as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.