Kidwind
unread,Oct 22, 2009, 12:06:04 AM10/22/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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该怎么办???