[英]'ImportError: no module named admin' when trying to follow the Django Girls tutorial
I am currently doing the Django Girls tutorial, and I have hit a road block in which I can't python manage.py migrate
because bash complains that there aren't any modules named admin.我目前正在做 Django Girls 教程,我遇到了一个障碍,我无法python manage.py migrate
,因为 bash 抱怨没有任何名为 admin.admin 的模块What can I do?我能做些什么? I have done everything as the tutorial said.我已经按照教程所说的做了一切。 I am running bash through pythonanywhere.com, and this the error message:我正在通过 pythonanywhere.com 运行 bash,这是错误消息:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/wost/my-new-blog/myvenv/local/lib/python2.7/site-packages/djan
go/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/wost/my-new-blog/myvenv/local/lib/python2.7/site-packages/djan
go/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/wost/my-new-blog/myvenv/local/lib/python2.7/site-packages/djan
go/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/wost/my-new-blog/myvenv/local/lib/python2.7/site-packages/djan
go/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/wost/my-new-blog/myvenv/local/lib/python2.7/site-packages/djan
go/apps/config.py", line 123, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named admin
I suspect you have the following in INSTALLED_APPS
: 我怀疑你在INSTALLED_APPS
有以下内容:
INSTALLED_APPS = [
# ...
"admin",
# ...
]
I think you meant to use django.contrib.admin
instead: 我认为你的意思是使用django.contrib.admin
:
INSTALLED_APPS = [
# ...
"django.contrib.admin",
# ...
]
It seems like there is no model like admin
and you're still trying to import it. 似乎没有像admin
这样的模型,你仍然试图导入它。 Post your settings.py
. 发布你的settings.py
。 As I'm guessing you probably had added admin
inside INSTALLED_APP
like 正如我猜你可能在INSTALLED_APP
添加了admin
一样
INSTALLED_APPS = [
'django.contrib.admin',
'admin',
.......
]
If it's then remove that admin
and make it clear like assuming you haven't created any application in entire project 如果是,那么删除该admin
并明确表示你没有在整个项目中创建任何应用程序
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
]
And second thing I'm thinkin' of is that you might not had activated your project's virtual environment. 我想到的第二件事是你可能没有激活项目的虚拟环境。 Sometimes, this causes probs like this. 有时,这会导致像这样的问题。 And for that just change prompt
to where your manage.py
is located and just hit ..\\Scripts\\activate
(Windows) or ../Scripts/activate
(Unix like OSs). 而对于刚刚更改prompt
到您的manage.py
所在,只是打..\\Scripts\\activate
(Windows)或../Scripts/activate
(类似Unix的操作系统)。
I was stuck on the same thing; 我被困在同一件事上; the problem was the statement in urls.py: 问题是urls.py中的声明:
path('admin/', include('admin.site.urls'))
Instead the right line is 相反,正确的是
path('admin/', admin.site.urls)
Hope this helps! 希望这可以帮助!
I had the same problem and it turns outs the problem is I was in the wrong virtual environment and the wrong path file.我遇到了同样的问题,事实证明问题是我在错误的虚拟环境和错误的路径文件中。 Confirm that and it might save you a lot of work in debugging and changing the code which was working initially.确认这一点,它可能会为您节省大量调试和更改最初工作的代码的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.