Cannot start django application

I am new to Django, and every time I try to run python panel/manage.py startapp %app% (the panel is my project), it gives me an error:

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

Am I doing something wrong?

Surely companies or contacts or statistics are not the name of an existing Python module?

+8
source share
12 answers

Maybe you need

 cd panel python manage.py startapp yourappname 

I'm not sure that executing a command from a directory on your project will work correctly.

+7
source

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

+10
source

I was confused too, until I realized that the Django project is a container for applications; this sequence makes it 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 ... 
+10
source

This message is displayed if you run "startapp" twice with the same application name. As mentioned above, the OP does not restart the application, it creates it.

+2
source

I think you may have already created the dir application in the dir panel manually. The "startapp" command is designed to automatically create an application. If you already have it, it does not work.

+2
source

Try the classic mysite or myproject. You can delete it at any time, so if it is accepted, all your personal ideas contradict the Python modules.

Edit: I tried all your ideas, there were no errors for me. So, if you installed support libraries or modules for django, then some of them may contain such names.

+1
source

I had the same problem because I tried to "reload" my application after making the changes, but startapp is for one-time use to create a new application. To view the changes, synchronize the application with the database using python manage.py migrate and restart the server using python manage.py runserver .

From django-admin docs

( manage.py does essentially the same as django-admin )

startapp <app_label> [destination]

django-admin startapp

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

By default, the created directory contains the models.py file and other application template files. (See the source for details.) If only the application name is specified, the application directory will be created in the current working directory.

If an additional destination is provided, Django will use the existing one instead of creating a new one. You can use '. indicate the current working directory.

For instance:

django-admin startapp myapp /Users/jezdez/Code/myapp

+1
source

This is a process, as I understand it, that I doubt it.

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

Then I ran python manage.py runningerver and it works well.

Then, as suggested on this page, I used the 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 this directory and ran the startapp command with the same name, and it worked perfectly.

So, the "startapp" command is designed to automatically create an application. If you already have it, it does not work.

The answer given by @DAG worked for me.

+1
source

this error occurs due to name conflicts between the application name and the project name. You have provided the same name for your application and project. Your project and application must have a different name. If you gave the same name, the above error will occur.

understand the difference between an application and a project

Projects and Applications

What is the difference between a project and an application? An application is a web application that does something — for example, a Weblog system, a database of public records, or a simple polling application. A project is a collection of configurations and applications for a specific website. A project may contain several applications. An application can be in several projects.

first create a project. , then create the application.

NOTE: the name for the application and the project must be different

first create a project with the project name

  django-admin.py startproject Projectname . 

Then create an application with the name of the application. (to create the application, make sure that you are in the same manage.py directory and enter this command)

 python manage.py startapp Appname 
0
source

You must choose different names for your project and application in the codes:

 django-admin startproject **my_project** python manage.py startapp **my_app** 
0
source

I reproduced the problem, and there is actually something not working as I expected. I wonder if we stumbled upon the mistake of Django or a restriction that I do not understand?

Having a project called "project" and an empty app / newapp folder ... I tried:

 python manage.py startapp newapp apps/newapp 

Returns:

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

But if I aim for ANY other route in which the last folder is not named with the same name as the application that I run, it works.

So, I finished doing:

 python manage.py startapp newapp apps/main 

Using Django 2.1.3.

0
source

I ran into this problem while trying to set up a Wagtail project.

Before creating the application, I created and activated virtualenv (using virtualenvwrapper) with the same name: $ APPNAME. When I then launched wagtail start $APPNAME , Django looks for name conflicts in $ PYTHONPATH, which in this case points to /Users/User/.virtualenvs.

Naturally, this leads to a conflict, since /Users/User/.virtualenvs/$APPNAME already exists.

0
source

Source: https://habr.com/ru/post/894775/


All Articles