Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

startapp with manage.py to create app in another directory

Tags:

python

django

My Django project structure is:

/proj   /frontend   /server     /proj     /app1     /app2   manage.py 

How do I run python manage.py startapp app_name so that my newly created apps are within the /server directory? I tried running django-admin.py startapp appname within the server directory to create the app but I would end up with this error:

$ ./manage.py runserver Traceback (most recent call last):   File "./manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line     utility.execute()   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 177, in fetch_command     commands = get_commands()   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper     result = user_function(*args, **kwds)   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 72, in get_commands     for app_config in reversed(list(apps.get_app_configs())):   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs     self.check_apps_ready()   File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready     raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. 
like image 381
Liondancer Avatar asked Oct 20 '15 18:10

Liondancer


People also ask

What is the difference between Startproject and Startapp in Django?

The startproject will create the main project directory, while the startapp will create the app directory. Both are also been passed a name to be used in generation. The startproject is the first command run when creating a new project, while the startapp is run inside the new project directory.

What is manage Py used for?

It is your tool for executing many Django-specific tasks -- starting a new app within a project, running the development server, running your tests... It is also an extension point where you can access custom commands you write yourself that are specific to your apps.

Where is manage PY located?

The django-admin.py script should be on your system path if you installed Django via its setup.py utility. If it's not on your path, you can find it in site-packages/django/bin within your Python installation.


1 Answers

You can specify the path to /server/appname directory after appname as the destination i.e. where the Django app directory structure will be created.

From the startapp docs:

startapp <app_label> [destination] # startapp command usage  

Creates a Django app directory structure for the given app name in the current directory or the given destination.

If only the app name is given, the app directory will be created in the current working directory.

If the optional destination is provided, Django will use that existing directory rather than creating a new one

So, you can specify the path to your /server/appname directory as the destination value.

django-admin.py startapp appname [destination] # specify destination 

What you need to do?

1. You need to first create a directory appname inside /server.

mkdir /server/appname # create directory from root level 

2. Then, run the startapp command to create the app.

django-admin.py startapp appname ./server/appname 
like image 137
Rahul Gupta Avatar answered Oct 12 '22 13:10

Rahul Gupta