Django1.3 add the solution that app prompt module does not exist

  • 2020-04-02 14:00:12
  • OfStack

When using Django to add applications, you are always prompted with Error: No module named myapp. This means that I cannot find the application with this name, but I have succeeded in startapp and the system has created the corresponding directory


D:Python27Scriptswebsite>python manage.py syncdb
Error: No module named myapp

Is there anything wrong with the official documentation? I managed. Py startapp myapp has been successful and I have created directories and files.
Add the application in INSTALLED_APPS of settings.py, as shown in the following code

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'website.myapp',
)

The last line website.myapp is the one I added. Google searched for a long time, also did not solve this problem. Finally had to go to the official reading docs, only to find that this is the new version and the old version of the difference.
Project. App was required to write this before Django1.3
After version 1.3 of django, you just need to write the app like this
Finally, change INSTALLED_APPS of settings.py to

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'myapp',
)

Then perform

python manage.py syncdb

OK, success.

Afterword.

I downloaded the latest version of Django1.4 and the tutorial is from the old version. Step by step with the tutorial installation problems, at first, I thought I was where the command is missing or wrong command, retry N times or prompt can not find the application. Finally, I had no choice but to go to the official website to carefully read the English manual (by translation software) and finally found that this is the version of the problem.

After a few days of debugging found that the new version and the old version there are many differences, but also is a novice and easy to make mistakes, and the web very few tutorials are based on the low version, plus many sites collection of sameness, this may be because Python in the domestic sites almost no or very few. So personal advice contact Django1.3 version of more than children's shoes encountered problems best read the official website manual, generally can not find a solution online.


Related articles: