在Django找不到View

时间:2012-08-20 23:02:46

标签: python django

我收到错误

在/的ViewDoesNotExist 无法导入blog.views。模块博客中不存在视图。

使用Django

我的URLS文件如下所示

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'blog.views.home', name='home'),
    # url(r'^Blog/', include('Blog.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

我的目录树看起来像这样

Blog
_manage.py
_Blog
__wsgi.py
__urls.py
__settings.py
__ __init__.py
_blog
__views.py
__tests.py
__Templates
____index.html
__models.py
__ __init__.py

并在views.py

from django.shortcuts import render_to_response

from blog.models import posts

def home(request):
    return render_to_response('index.html')

进一步调试:

Environment:


Request Method: GET
Request URL: http://192.168.2.3:1337/

Django Version: 1.4.1
Python Version: 2.7.3
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 "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  300.                     sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  209.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in callback
  216.         self._callback = get_callable(self._callback_str)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in wrapper
  27.         result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in get_callable
  101.                     (lookup_view, mod_name))

Exception Type: ViewDoesNotExist at /
Exception Value: Could not import blog.views. View does not exist in module blog.

3 个答案:

答案 0 :(得分:8)

根据您的调试输出,似乎博客应用程序在settings.py中的INSTALLED_APPS设置中不存在

答案 1 :(得分:2)

显然你忘了把你的'博客'应用程序包含在settings.py

上的django安装的应用程序中

答案 2 :(得分:0)

检查您的命名中的大小写,并确保您的应用中有 init .py。