2014-01-26 66 views
0

我想使用Django的通用視圖,但運行時出現錯誤python manage.py runserver。我已經四處尋找遇到此問題並沒有發現任何問題的人。下面是我的項目的urls.py URL模式:Django無法導入通用視圖django.views.generic.date_based.object_detail

(r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 
    'django.views.generic.date_based.object_detail', entry_info_dict), 

而這裏的錯誤:

Unhandled exception in thread started by <function wrapper at 0x10c946668> 
Traceback (most recent call last): 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper 
    fn(*args, **kwargs) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run 
    self.validate(display_num_errors=True) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate 
    num_errors = get_validation_errors(s, app) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors 
    for (app_name, error) in get_app_errors().items(): 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors 
    self._populate() 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate 
    self.load_app(app_name, True) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app 
    models = import_module('%s.models' % app_name) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module 
    __import__(name) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module> 
    patch_root_urlconf() 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf 
    reverse('djdt:render_panel') 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 480, in reverse 
    app_list = resolver.app_dict[ns] 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 310, in app_dict 
    self._populate() 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 285, in _populate 
    lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args)) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 229, in callback 
    self._callback = get_callable(self._callback_str) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 32, in wrapper 
    result = func(*args) 
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 103, in get_callable 
    (lookup_view, mod_name)) 
django.core.exceptions.ViewDoesNotExist: Could not import django.views.generic.date_based.object_detail. Parent module django.views.generic.date_based does not exist. 

有誰知道我可能是錯在這裏做什麼?

+0

您正在使用什麼版本的Django的? – yuvi

+0

相關:[什麼是當前Django的「從django.views.generic進口list_detail」?](https://stackoverflow.com/questions/21361646/django-cant-import-generic-view-django-views-generic-date基於對象細節) – user2314737

回答

3

您需要使用Django < 1.5才能使用基於函數的通用視圖。 They were depreciated in 1.3和1.5取出代替class based generic views

As a result of the introduction of class-based generic views, the function-based generic views provided by Django have been deprecated. The following modules and the views they contain have been deprecated:

  • django.views.generic.create_update
  • django.views.generic.date_based
  • django.views.generic.list_detail
  • django.views.generic.simple

這裏是the documentation for the new generic class based date views,特別是DateDetailView