Django Python 1.5.1抛出导入错误

时间:2013-06-26 05:18:56

标签: python django

我是Django的新手并且遵循此链接中提到的教程:

http://www.djangobook.com/en/2.0/index.html

一切顺利,直到我来到第3章创建Hello World的部分:

http://www.djangobook.com/en/2.0/chapter03.html

我相信我已经遵循了所有内容 - 但是当我尝试访问该网站时:

http://127.0.0.1:8000/hello/

我收到以下错误:

/ hello /

中的ImportError

没有名为views的模块

以下是此错误的回溯信息:


Environment:

Request Method: GET
Request URL: `http://127.0.0.1:8000/hello/`

Django Version: 1.5.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "E:\DPF\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  103.                     resolver_match = resolver.resolve(request.path_info)
File "E:\DPF\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
  319.             for pattern in self.url_patterns:
File "E:\DPF\Python27\lib\site-packages\django\core\urlresolvers.py" in url_patterns
  347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "E:\DPF\Python27\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
  342.             self._urlconf_module = import_module(self.urlconf_name)
File "E:\DPF\Python27\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "E:\Work\Documents\Sites\mysite\mysite\urls.py" in <module>
  2. from mysite.views import hello

Exception Type: ImportError at /hello/
Exception Value: No module named views

目录结构如下:

mysite--
    mysite--
        __init__.py
        __init__.pyc
        settings.py
        settings.pyc
        urls.py
        urls.pyc
        wsgi.py
        wsgi.pyc
    django.db
    manage.py
    views.py

知道可能出了什么问题吗?

此致 Indrajit

1 个答案:

答案 0 :(得分:0)

您是否在settings.py

中将<appname>添加到INSTALLED_APPS

然后仍然是错误的,

如果您从项目文件夹(django-admin.py startapp <appneam>

运行\<mainfolder>\<projectfolder>

你想尝试:

from <yourprojectname>.<yourappname>.views import hello

或者您从文件夹中运行django-admin.py startapp <appneam>包含manage.py(即\<mainfolder>\)。

然后执行所有必要的步骤,然后尝试:

from <yourappname>.views import hello

实际上djangobook已经过时且不经常更新。