如何自定义Django里的widget啊,为啥会出错?

8 views
Skip to first unread message

Kidwind

unread,
Oct 22, 2009, 12:06:04 AM10/22/09
to Django-Chinese
想实现一个Html编辑器的widget,widgets.py代码如下:

from django.forms.widgets import Textarea
from django.utils.safestring import mark_safe
from util import flatatt
from django.utils.html import escape, conditional_escape
from django.utils.encoding import StrAndUnicode, force_unicode

class FckEditor(Textarea):
def __init__(self, attrs=None):
super(FckEditor, self).__init__(attrs)

def render(self, name, value, attrs=None):
super(FckEditor, self).render(name, value, attrs)

forms.py代码如下:
from django import forms
import books

TOPIC_CHOICES = (
('general', 'General enquiry'),
('bug', 'Bug report'),
('suggestion', 'Suggestion'),
)

class ContactForm(forms.Form):
topic = forms.ChoiceField(choices=TOPIC_CHOICES)
message = forms.CharField(widget = books.widgets.FckEditor())
sender = forms.EmailField(required=False)

def clean_message(self):
message = self.cleaned_data.get('message', '')
num_words = len(message.split())
if num_words < 4:
raise forms.ValidationError("Not enough words!")
return message



运行时出错,提示
ViewDoesNotExist at /contact/
Tried contact in module src.books.views. Error was: 'module' object
has no attribute 'widgets'


怎么回事啊???要实现自己的widget该怎么办???
Reply all
Reply to author
Forward
0 new messages