【问题标题】:Python Django ImportError: No module named websitePython Django ImportError:没有名为网站的模块
【发布时间】:2013-07-24 11:32:29
【问题描述】:

我在 Django 1.5.1 上运行一个示例站点,但在创建名为“website”的 Django 应用程序时出现 ImportError。这是我的应用层次结构。

TrackLeech
  -- __init__.py
  -- manage.py
  TrackLeech
    -- __init__.py
    -- setting.py
    -- urls.py
    -- wsgi.py
  website
    -- __init__.py
    -- models.py
    -- tests.py
    -- views.py
    templates
      -- index.html

现在当我运行命令时,服务器在 8000 端口启动良好,但 localhost:8000 页面显示 ImportError

$ python manage.py runserver

Validating models...

0 errors found
July 24, 2013 - 13:29:03
Django version 1.5.1, using settings 'TrackLeech.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site-              packages/Django-1.5.1-py2.7.egg/django/core/handlers/base.py", line 103, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site-    packages/Django-1.5.1-py2.7.egg/django/core/urlresolvers.py", line 321, in resolve
    sub_match = pattern.resolve(new_path)
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site-   packages/Django-1.5.1-py2.7.egg/django/core/urlresolvers.py", line 223, in resolve
    return ResolverMatch(self.callback, args, kwargs, self.name)
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site- packages/Django-1.5.1-py2.7.egg/django/core/urlresolvers.py", line 230, in callback
    self._callback = get_callable(self._callback_str)
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site-    packages/Django-1.5.1-py2.7.egg/django/utils/functional.py", line 29, in wrapper
    result = func(*args)
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site- packages/Django-1.5.1-py2.7.egg/django/core/urlresolvers.py", line 101, in get_callable
    not module_has_submodule(import_module(parentmod), submod)):
  File "/home/chitrank/Documents/Google_App_Engine/venv/local/lib/python2.7/site-  packages/Django-1.5.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named website

我无法确定这是新 Django 版本 1.5.1 中的错误,或者我正在以不同的方式制作模块,或者我应该重新安装 Django 还是应该使用其他 Django 版本。请建议我是否需要更改我正在使用的 Django?

【问题讨论】:

  • INSTALLED_APPS的网站吗?
  • 是的,我已经在 INSTALLED_APPS 中列出了我的 django 应用程序。
  • 您是否按照正确的文档来开始您的 django 项目?因为它从一个版本到另一个版本发生了很大变化。
  • 我在 net.tuts net.tutsplus.com/tutorials/python-tutorials/… 上观看了这个截屏视频,他们使用了 Django 1.3,Django 是否将其从 Django 1.3 更改为 1.5

标签: python django django-1.5


【解决方案1】:

您必须确保以基本方式创建应用程序:python manage.py startapp 网站并在设置 INSTALLED_APPS 中设置应用程序的名称。

【讨论】:

    【解决方案2】:

    嘿,“登录”名称我也面临同样的问题。

    我的应用名称是“login”,并且具有相同的 feature.py。

    当我尝试使用导入功能时

     from login import feature
    

    IDE 没有显示任何问题。智能感知工作正常。

    但是当我尝试运行服务器时,它抛出 ImportError: No module named feature。 一旦我将登录名更改为扩展登录名,它就起作用了。

    所以我认为某些关键字不能用作应用名称。您尝试更改应用名称。

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 2018-01-16
      • 2013-05-04
      • 2017-07-01
      • 2014-03-19
      • 2012-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多