简体   繁体   English

Django教程1 - ImportError:没有名为apps的模块

[英]Django Tutorial 1 - ImportError: No module named apps

I am following this Tutorial: https://docs.djangoproject.com/en/1.10/intro/tutorial02/ 我正在关注这个教程: https//docs.djangoproject.com/en/1.10/intro/tutorial02/

In subsection "Activating models" i should add some code in the “激活模型”小节中,我应该添加一些代码

mysite/settings.py mysite的/ settings.py

INSTALLED_APPS = [
  'polls.apps.PollsConfig',
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
]

when i run the command 当我运行命令

python manage.py makemigrations polls

i get the following errormessage 我得到以下错误消息

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib/python2.7/dist-packages/django/apps/config.py", line 112, in create
    mod = import_module(mod_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named apps

i don't have a folder or a file called "apps" in my "polls" folder, so i am wondering about the "polls.apps.PollsConfig" syntax. 我的“polls”文件夹中没有名为“apps”的文件夹或文件,所以我想知道“polls.apps.PollsConfig”语法。 i found some posts in the web telling that in django version 1.7 there where some changes. 我在网上发现了一些帖子,告诉你在django 1.7版中有一些变化。

I am using: 我在用:

  • Ubuntu 16.04 LTS Ubuntu 16.04 LTS
  • Python 2.7.11+ Python 2.7.11+
  • django.VERSION (1, 8, 7, 'final', 0) django.VERSION(1,8,7,'final',0)

You're using a newer version of Django, who doesn't create the app.py configuration file in the folder because the old structure is different. 您正在使用较新版本的Django,它不会在文件夹中创建app.py配置文件,因为旧结构不同。 You've two options: 你有两个选择:

1) Change the documentation version to 1.8 1)将文档版本更改为1.8

2) [RECOMMENDED] use the latest version of Django 2)[推荐]使用最新版本的Django

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM