cookiecutter/cookiecutter-django

New apps created are located in the project root, not inside the project slug

jecepeda opened this issue ยท 7 comments

What happened?

When creating a new app using python manage.py startapp <name-of-the-app>, the application is created within the project root

What should've happened instead?

The application should be created within the project slug, as indicated here

Steps to reproduce

  • Create a bare new application using cookiecutter-django
  • Install all requirements into your virtualenvironment using pip install -r requirements/local.txt
  • Try to create a new app (with the name foo, for instance) using python manage.py startapp foo

@JCepedaVillamayor

What happened?
When creating a new app using python manage.py startapp , the application is created within the project root

this is the expected behavior, because cookiecutter-django does not change the way that django startapp works. ( I tried doing this in another branch, but, I did not like having to rewrite almost everything to include this relatively simple logic. the django startapp, apparently, was not projected to be extended ๐Ÿ˜ข )

you'll have to fix this manually:

1 - create the <name-of-the-app> app with python manage.py startapp
2 - move <name-of-the-app> directory to <project_slug> directory
3 - edit <project_slug>/<name-of-the-app>/apps.py and
change name = "<name-of-the-app>" to name = "<project_slug>.<name-of-the-app>"
4 - add "<project_slug>.<name-of-the-app>.apps.<NameOfTheAppConfigClass>", on your LOCAL_APPS on config/settings/base.py

if that is enough to answer the question. please close this issue.
We gladly accept code and documentation contributions.

Oh, I see, I misunderstood the meaning of the comment. Thank you for the manual fix, this was the steps I were doing before.

I'll be glad to document the project if needed (maybe on Troubleshooting?)

I close the issue for now, let's see how we proceed then.

Why am I getting a ModuleNotFoundError: No module named '<project_slug>.<name-of-the-app>.urls' when I add the new app onto the config/urls.py? I followed the above example but got the error when running the local server

As a newcomer to both Django and cookiecutter-django, I was confused by two aspects related to this issue:

  1. I created a "Polls" app (from the Django tutorial) to compare both structures, and realized they were different
  2. It was not clear to me, after having run cookiecutter-django, whether I needed to also explicitly create an app afterward or not (it seems that it is the case, because only the "Users" app is created right after the project has been generated)

This would seem to be a subject/issue worthy of documentation, perhaps inclusion in the startapp work flow. I see manual fixes presented as a reply to an issue, but surely this is worth addressing to the wider audience who may not come into the issues for a solution? Is this just me?

I'm not sure if it helps, but here is what I do:

  • cd into the project_slug directory
  • run python ../manage.py startapp <name_of_app>

This way it is created inside the project_slug directory.

I found a great way to solve this issue.
To execute it, navigate to the desired directory and run the command django-admin startapp <app_name>.
This allows you to easily organize your apps in separate folders.