简体   繁体   中英

'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.What can I do? I have done everything as the tutorial said. I am running bash through pythonanywhere.com, and this the error message:

    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 = [
    # ...
    "admin",
    # ...
]

I think you meant to use django.contrib.admin instead:

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

It seems like there is no model like admin and you're still trying to import it. Post your settings.py . As I'm guessing you probably had added admin inside INSTALLED_APP like

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

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).

I was stuck on the same thing; the problem was the statement in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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