Django ViewDoesNotExist错误

时间:2012-05-21 16:58:48

标签: python django

我刚刚迁移到另一个操作系统,在复制了完美的精彩django项目后,我在尝试加载管理页面时遇到了ViewDoesNotExist错误。

我删除了urls.py文件中指向违规视图功能的行但是django只是抱怨它上面的url指向的视图,所以我删除了它,没有快乐:(。我最终删除除logs网址之外的所有项目网址,以使其运行管理页面

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/

Django Version: 1.4
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',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'south',
 'uni_form',
 'treebeard',
 'dojango',
 'item',
 'letter')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'clientms.middleware.EnforceLoginMiddleware',
 'dojango.middleware.DojoCollector')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in wrapper
  213.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  196.             return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in index
  353.                             model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info, current_app=self.name)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
  447.                 app_list = resolver.app_dict[ns]
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in app_dict
  290.             self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
  253.                     for name in pattern.reverse_dict:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
  276.             self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
  265.                 lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
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 /admin/
Exception Value: Could not import letter.views.import_uploader. View does not exist in module letter.views.

setting.py

# Django settings for clientms project.

import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

# TODO: replace all case of 'if something:' with 'if something is None:'

MANAGERS = ADMINS

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'xxxx',              # Or path to database file if using sqlite3.
    'USER': 'xxxx',         # Not used with sqlite3.
    'PASSWORD': 'xxxx',     # Not used with sqlite3.
    'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

SITE_URL = 'http://localhost:8000'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Europe/London'

COUNTRY_CODE = '+44'
USER_VARIABLES = 'bool1','bool2','bool3','bool4','bool5','int1','int2','float1','float2','float3','date1','date2','string1','string2'
# TODO: this should be used with the item history for 'client', 'file', 'alarm', 'communication' and 'letters' in the item view
SHORT_HISTORY_LENGTH = 5
LETTER_EDITOR_HEIGHT = 400  # Height of the editor for letters and templated letters

# TODO: Make sure english dates work when deployed (???)

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-gb'
#DATE_INPUT_FORMATS = ('%d-%m-%Y','%Y-%m-%d')

SITE_ID = 1
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = False

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
NUMBER_GROUPING = 3
THOUSAND_SEPARATOR = ','
USE_THOUSANDS_SEPARATOR =True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ( os.path.join(SITE_ROOT, 'static/files'))

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = SITE_URL+'/files/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ( os.path.join(SITE_ROOT, 'static/static'))

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    #( os.path.join(SITE_ROOT, 'static/static')),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    # Common
    'django.middleware.common.CommonMiddleware',
    # Session
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    # Authentication
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    # Mesages (deep phython I think!)
    'django.contrib.messages.middleware.MessageMiddleware',
    # Force Login
    'clientms.middleware.EnforceLoginMiddleware',
    # Dojango Form stuff
    'dojango.middleware.DojoCollector',
)

LOGIN_URL = '/log/in/'

PUBLIC_URLS = (
    r'log/in/',
    r'admin/',
    r'static/',
    r'dojango/dojo-media/',
    r'dojango/test/',
)

ROOT_URLCONF = 'clientms.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    '/home/arthur/Software/django/clientms/login/templates',
    '/home/arthur/Software/django/clientms/ajaxuploader/templates',
    '/home/arthur/Software/django/clientms/item/templates',
    '/home/arthur/Software/django/clientms/letter/templates',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'south',
    'uni_form',
    'treebeard',
    'ajaxuploader',
    'dojango',
    'item',
    'letter',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
    'mail_admins': {
        'level': 'ERROR',
        'class': 'django.utils.log.AdminEmailHandler'
    }
    },
    'loggers': {
    'django.request': {
        'handlers': ['mail_admins'],
        'level': 'ERROR',
        'propagate': True,
    },
    }
}

urls.py

from django.conf.urls.defaults import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

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

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'clientms.views.home', name='home'),
    # url(r'^clientms/', include('clientms.foo.urls')),
    url(r'^$', 'page.views.main_view'),
    url(r'^settings/', include('clientms.page.urls_settings')),
    url(r'^countries/$', 'page.views.test_countries'),
    url(r'^home/$', 'page.views.home_view'),
    url(r'^item/', include('clientms.item.item_urls')),
    url(r'^letter/', include('clientms.letter.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)),

    #url(r'^dojango/', include('dojango.urls')),
    # Logs you in and out of the app
    url(r'^log/', include('login.urls')),
)

# DEVELOPMENT ONLY !!!
urlpatterns += staticfiles_urlpatterns()

为什么django会抱怨它在项目中找不到任何视图? (而且它不是权限的东西[chmod])

EXTRA:错误页面中的任何内容都指向我的任何文件(只有django corecontribviewsutils

EXTRA !:当我加载localhost:8000时,另一个注意事项是

[21/May/2012 17:55:43] "GET /static/messages/messages.css HTTP/1.1" 304 0
[21/May/2012 17:55:43] "GET /static/tiny_mce/tiny_mce.js HTTP/1.1" 304 0
[21/May/2012 17:55:43] "GET /static/jquery-1.7.2.min.js HTTP/1.1" 304 0
[21/May/2012 17:55:43] "GET /static/ajaxuploader/js/fileuploader.js HTTP/1.1" 404 1697
[21/May/2012 17:55:43] "GET /static/ajaxuploader/css/fileuploader.css HTTP/1.1" 404 1703
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojo/dojo.js HTTP/1.1" 404 3424
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojango/dojango.js HTTP/1.1" 404 3442
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dijit/themes/claro/claro.css HTTP/1.1" 404 3472
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojo/resources/dojo.css HTTP/1.1" 404 3457
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojox/form/resources/FileInput.css HTTP/1.1" 404 3490
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojo/dojo.js HTTP/1.1" 404 3424
[21/May/2012 17:55:43] "GET /dojango/dojo-media/1.6.1/dojango/dojango.js HTTP/1.1" 404 3442
[21/May/2012 17:55:43] "GET /static/ajaxuploader/js/fileuploader.js HTTP/1.1" 404 1697
[21/May/2012 17:55:43] "GET /static/ajaxuploader/css/fileuploader.css HTTP/1.1" 404 1703

所有文件夹都具有相同的权限,因此我不知道为什么它会加载一些静态文件而不加载其他文件

2 个答案:

答案 0 :(得分:2)

我能想到的一件事是在Django 1.4中更改的文件夹结构,如果你来自Django 1.3,请确保在卸载1.3之前删除/usr/local/bin/django-admin.py你安装1.4。     由于安装冲突,我在munged文件夹结构和错误的python路径上遇到了类似的问题。     我做的一个稍微脏的解决方案是在1.4中创建一个新项目,然后将旧安装中的文件复制到新的文件夹结构中,除了我留在其中的新manage.py位置。

答案 1 :(得分:0)

最有可能的唯一区别是你的环境。您的静态媒体将继续加载,因为它在文件系统上的相对性和django知道在哪里看(与模板相同)。它的动态(或在settings.py中明确引用)

你可能缺少的是你的PYTHONPATH中的django项目

export PYTHONPATH=/path/to/django/project:$PYTHONPATH