使用manage.py startapp在另一个目录中创建应用 [英] startapp with manage.py to create app in another directory
问题描述
我的 Django
项目结构是:
/proj
/frontend
/server
/proj
/app1
/app2
manage.py
我如何运行 python manage.py startapp app_name
,以便我新创建的应用位于<$ c $之内c> /服务器目录?我尝试在 server
目录中运行 django-admin.py startapp应用名称
创建应用,但是最终此错误:
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.
推荐答案
您可以指定<$ appname
之后的c $ c> / server / appname 目录作为目的地
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.
startapp <app_label> [destination] # startapp command usage
为Django应用创建目录结构
当前目录中的给定应用程序名称或给定目的地。
如果仅给出了应用程序名称,则该应用程序目录将在当前工作目录的
中创建。
If only the app name is given, the app directory will be created in the current working directory.
如果提供了可选目标位置,则Django将使用现有的
目录而不是创建新目录一个
If the optional destination is provided, Django will use that existing directory rather than creating a new one
因此,您可以指定 / server / appname
的路径目录作为目的地
值。
So, you can specify the path to your /server/appname
directory as the destination
value.
django-admin.py startapp appname [destination] # specify destination
您需要做什么?
1。。首先需要在内创建目录
。 appname
/ server
1. You need to first create a directory appname
inside /server
.
mkdir /server/appname # create directory from root level
2。。然后,运行 startapp
命令来创建应用。
2. Then, run the startapp
command to create the app.
django-admin.py startapp appname ./server/appname
这篇关于使用manage.py startapp在另一个目录中创建应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!