无法导入setting.views.types。模块setting.views中不存在视图

时间:2013-09-09 09:46:41

标签: python django django-models django-forms

widgets.py

from django.utils.safestring import mark_safe
from django.forms.widgets import Widget, Select
from django import forms
from django.conf import settings


class CheckboxDivSelectMultiple(CheckboxSelectMultiple):
'''renders the checkboxes as divs with a hard coded class'''

def render(self, name, value, attrs=None, choices=()):
    if value is None: value = []
    has_id = attrs and 'id' in attrs
    final_attrs = self.build_attrs(attrs, name=name)
    output = [u'<div>']
    """""""""
        option_label = conditional_escape(force_unicode(option_label))
        output.append(u'<div class="%s"><label%s>%s %s</label></div>' % ('new-class', label_for, rendered_cb, option_label))
    output.append(u'</div>')
    return mark_safe(u'\n'.join(output))

forms.py

class TypeSelectionForm(forms.Form):
    checkbox_field = forms.MultipleChoiceField(widget=forms.CheckboxDivSelectMultiple(), label="", required=False)

我正在使用自定义小部件覆盖checkboxselectmultiple。我将小部件代码放在widgets.py中。返回错误“ViewDoesNotExist at / setting / type /”

回溯:

Environment:

Request Method: GET
Request URL: http://192.168.100.12/setting/type/

Django Version: 1.4.1
Python Version: 2.7.0

Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  300.                     sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  300.                     sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  209.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
  216.         self._callback = get_callable(self._callback_str)
File "/usr/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
  27.         result = func(*args)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
  101.                     (lookup_view, mod_name))

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

1 个答案:

答案 0 :(得分:0)

根据您的导入,不应该这一行:

class CheckboxDivSelectMultiple(CheckboxSelectMultiple):
是吗?

class CheckboxDivSelectMultiple(forms.CheckboxSelectMultiple):