ImportError: No module named app_name

萝らか妹 提交于 2019-12-11 05:07:55

问题


I am new to python and I have seen similar questions on SO but not able to figure out whats wrong with my Django app.

In settings.py I have added my app in dotted module form :

INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'mproject.blog',
)

and the Traceback :

D:\py pro\mproject>python manage.py runserver 9999
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
    translation.activate('en-us')
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
    return _trans.activate(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
ImportError: No module named blog

In manage.py I have

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mproject.settings")

How to resolve this issue ?


回答1:


I don't think you need to use myproject.blog.

Just add blog to the installed apps. Thats enough.



来源:https://stackoverflow.com/questions/20866397/importerror-no-module-named-app-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!