问题描述
每次在Django应用的根服务器中键入python manage.py runserver时,都会出现此错误.
I'm getting this error every time I type python manage.py runserver in the root server of my Django app.
导入错误:没有名为utils的模块
我刚刚通过在项目的根目录(/ecomstore/)中运行python manage.py startapp utils向我的项目添加了一个名为"utils"的新应用,然后将其移动到了我的书中所说的放置目录中内.
I just added a new app to my project called 'utils' by running python manage.py startapp utils in the root directory of my project (/ecomstore/), and then moved it to the directory my book said to put it in.
下面是我的项目目录的概述,后面是我的代码:
Here's an overview of my project's directories, followed by my code:
manage.py
manage.py
settings.py
settings.py
urls.py
views.py
wsgi.py
catalog.py/
admin.py
forms.py
models.py
models.py
tests.py
urls.py
views.py
static.py/
catalog.html
catalog.html
css.css
模板/
目录/
catalog.html
catalog.html
index.html
index.html
标签/
实用程序/
models.py
models.py
tests.py
views.py
context_processors.py
context_processors.py
我的settings.py文件中的相关代码如下:
The relevent code from my settings.py file is below:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'catalog',
'utils',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
FWIW:我也尝试过将'ecomstore.utils'放在INSTALLED_APPS下,并将utils目录移动到项目的根目录.我的书叫做开始使用Django进行电子商务,而且已经过时了.在此先感谢您的帮助,我真的很受困扰!
FWIW: I have also tried putting 'ecomstore.utils' under INSTALLED_APPS, and moving the utils directory to the root directory of my project.My book is called Beginning Django for Ecommerce and it's outdated.Thanks in advance for any help, I'm really stuck!
推荐答案
- 应将实用程序从模板"上移至"ecomstore".
- 初始化文件应命名为
__ init __.py
,而不是init.py
. - 在目录中使用.py结尾很不常见
如果您的书过时了,我强烈建议您先进行django教程,并在此方法成功后,尝试使该书的内容适应您在教程中学到的内容.
I would strongly suggest to do teh django tutorial first if your book is outdated and after you succeed with this, try to adapt the book content to what you learned in the tutorial.
这篇关于python为什么找不到我的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!