Cannot start any django app

前端 未结 14 1577
离开以前
离开以前 2021-01-02 06:22

I am a newbie at Django and everytime I try to run python panel/manage.py startapp %app% (panel is my project) it gives me the error:

Error: \'         


        
相关标签:
14条回答
  • 2021-01-02 06:53

    This is a fun one - your project and your app need to have different names. You probably created a project, then tried to startapp with the same name.

    0 讨论(0)
  • 2021-01-02 06:54

    None of these answers helped me. In the end I ended up creating an app with a different name and then just renaming the directory to the app name I wanted all along. Note that you also will need to change the class name in apps.py to match your app name.

    0 讨论(0)
  • 2021-01-02 06:55

    I was confused as well, until I realized that a Django project is a container for applications; this sequence makes it a bit clearer:

    # first create a Project (container).
    django-admin.py startproject Project
    
    # create multiple apps
    cd Project
    python manage.py startapp polls
    python manage.py startapp hello
    ...
    
    0 讨论(0)
  • 2021-01-02 06:55

    It's the process how I got my doubt clear.

    First, I created a directory inside my project directory and put __init__.py, models.py, admin.py, apps.py & views.py.

    Then I ran python manage.py runserver & It work well.

    Then as suggested on that page I used startapp command. I got this error :

    CommandError: 'ucportal' conflicts with the name of an existing Python 
    module and cannot be used as an app name. Please try another name.
    

    After that I deleted that directory and ran startapp command with same name and it worked fine.

    So 'startapp' command is to create an app automatically. If you already have one there, it fails.

    Answer given by @DAG worked for me.

    0 讨论(0)
  • 2021-01-02 06:56

    You should choose different names for your project and app in Codes:

    django-admin startproject **my_project** 
    
    python manage.py startapp **my_app**
    
    0 讨论(0)
  • 2021-01-02 07:05

    I guess maybe you have already created the app's dir in panel dir manually. The command 'startapp' is to create an app automatically. If you already have one there, it fails.

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