我目前正在学习django并从Django Rest Framework学习教程。
问题如下。我有以下树:
.
./tutorial
./tutorial/manage.py
./tutorial/tutorial
./tutorial/tutorial/__init__.py
./tutorial/tutorial/__init__.pyc
./tutorial/tutorial/settings.py
./tutorial/tutorial/settings.pyc
./tutorial/tutorial/snippets
./tutorial/tutorial/snippets/__init__.py
./tutorial/tutorial/snippets/__init__.pyc
./tutorial/tutorial/snippets/admin.py
./tutorial/tutorial/snippets/apps.py
./tutorial/tutorial/snippets/apps.pyc
./tutorial/tutorial/snippets/migrations
./tutorial/tutorial/snippets/migrations/__init__.py
./tutorial/tutorial/snippets/models.py
./tutorial/tutorial/snippets/tests.py
./tutorial/tutorial/snippets/views.py
./tutorial/tutorial/urls.py
./tutorial/tutorial/wsgi.py
我通过添加
在settings.py中添加了依赖项'rest_framework',
'snippets.apps.SnippetsConfig',
在INSTALLED_APPS中。
问题是,当我做ElbattoresMacbook:tutorial elbattore$ python manage.py makemigrations snippets
时。我有以下错误:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/anaconda/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/anaconda/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/anaconda/lib/python2.7/site-packages/django/apps/config.py", line 142, in create
app_module = import_module(app_name)
File "/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named snippets
我做的有什么问题?我严格遵循http://www.django-rest-framework.org/tutorial/1-serialization/
但它不起作用......
谢谢你们
答案 0 :(得分:1)
你做了两次这个步骤:
$ docker-compose --version
docker-compose version 1.16.1, build 6d1ac219
$ docker --version
Docker version 17.09.0-ce, build afdb6d4
...最终在cd tutorial
内而不是./tutorial/tutorial
。
您可以通过将./tutorial
降低一个文件夹级别或将已安装的应用更改为snippets
来解决此问题。我建议将文件夹降低一级。您的结构应如下所示:
tutorial.snippets.apps.SnippetsConfig