尝试遵循Django Girls教程时,'ImportError:没有名为admin的模块'

时间:2016-04-23 20:43:20

标签: python django python-2.7

我目前正在做Django Girls教程,我遇到了一个障碍,我不能python manage.py migrate,因为bash抱怨没有任何名为admin的模块。我能做什么?正如教程所说,我做了一切。我正在通过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 

3 个答案:

答案 0 :(得分:2)

我怀疑你在int64Value中有以下内容:

let n = NSNumber(value: someInt64)
let m = n.int64Value  // m is an `Int64`

我认为您打算使用INSTALLED_APPS代替:

INSTALLED_APPS = [
    # ...
    "admin",
    # ...
]

答案 1 :(得分:1)

似乎没有像admin这样的模型,你仍在尝试导入它。发布您的settings.py。正如我猜你可能在admin内添加了INSTALLED_APP,如

INSTALLED_APPS = [
    'django.contrib.admin',
    'admin',
     .......
]

如果是,那么删除admin并明确表示你没有在整个项目中创建任何应用程序

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
]

我认为第二件事是您可能没有激活项目的虚拟环境。有时,这会导致像这样的问题。为此,只需将prompt更改为manage.py所在的位置,然后点击..\Scripts\activate(Windows)或../Scripts/activate(类似操作系统的Unix)。

答案 2 :(得分:1)

我被同一件事困住了;问题是urls.py中的语句:

path('admin/', include('admin.site.urls'))

右行是

path('admin/', admin.site.urls)

希望这会有所帮助!