startapp with manage.py to create app in another directory

前端 未结 6 892
谎友^
谎友^ 2021-01-31 14:25

My Django project structure is:

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

How do I run python ma

相关标签:
6条回答
  • 2021-01-31 14:50

    The simplest way I found is to go inside the server folder and create an __init__.py file:

    touch __init__.py
    

    Then, create any app you want:

    django-admin startapp {{APP NAME}}
    
    0 讨论(0)
  • 2021-01-31 14:52

    I always have my app in an internal folder (the same that Django creates, with the name of the project) following the design of Two Scoops of Django that is similar to what you want to do. When you want to create a new app, you can use, as the previous answer says,

    python ../manage.py startapp my_new_app
    

    from within the folder in which you want to create the app. Another thing, even easier that is what I do, is that you can run

    django-admin startapp my_new_app
    

    from this inner folder, of apps and it will work.

    0 讨论(0)
  • 2021-01-31 14:56

    Use absolute path for the manage file work well for me, an example to run from the destination folder

    python /home/user/project_name/manage.py startupapp app_name
    
    0 讨论(0)
  • 2021-01-31 15:04

    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
    
    0 讨论(0)
  • 2021-01-31 15:12

    If you are already in the server directory, then you can run

    python ../manage.py startapp appname
    

    And appname will be created in the server directory instead of in the project root.

    0 讨论(0)
  • 2021-01-31 15:16

    To Create a New App in Django project.

    First:

    • Go to your folder using Terminal, where you want to create app

    Second:

    • Type the below command in terminal,
    django-admin startapp <new_app_name>
    

    Now, you can check, new app created with the given name.

    0 讨论(0)
提交回复
热议问题