我正在尝试使用django-tinymce在我的表单中设置一个字段而没有成功,因为它只是在表单中显示一个普通的CharField。测试表单是使用Django crispy表单呈现的formset的一部分。
models.py
class test(models.Model)
test = models.CharField(max_length=100)
forms.py
from tinymce.widgets import TinyMCE
class TestForm(forms.ModelForm):
class Meta:
test = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
model = test
def __init__(self, *args, **kwargs):
super(TestForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = layout.Layout(
layout.Fieldset(
_("Test"),
layout.Field("test"),
),
)
urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'tripller.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^tinymce/', include('tinymce.urls')),
)
模板
{% load i18n crispy_forms_tags %}
<form method="post" action="." enctype="multipart/form-data">
{% csrf_token %}
{% crispy form %}
{{ formset.management_form }}
{{ formset.non_form_errors }}
{% for form in formset %}
{{ form.id }}
<div class="inline {{ formset.prefix }}">
{% crispy form %}
{{ form.description.errors }}
{{ form.description.label_tag }}
{{ form.description }}
</div>
{% endfor %}
</form>
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ajaxuploader',
'crispy_forms',
'tinymce',
)
TINYMCE_JS_URL = os.path.join(STATIC_ROOT, "js/tiny_mce/tiny_mce.js")
TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, "js/tiny_mce")
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
'plugins': "spellchecker",
'theme_advanced_buttons3_add': "|,spellchecker",
}
这是指定静态文件url的正确方法吗?我的所有js文件都存储在静态文件夹中而不是文档中建议的媒体文件夹中?由于参数定义不正确,CharField无法正常工作吗?
如何指定使用TinyMCE编辑器显示的文本字段?
假设用户通过TinyMCE完成表单编辑,如何以html格式显示提交的数据?
答案 0 :(得分:1)
字段定义应位于TestForm
级别,而不是TestForm.Meta
:
class TestForm(forms.ModelForm):
test = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
class Meta:
model = test
答案 1 :(得分:1)
尝试将表格放在library(dplyr)
test.df %>%
slice(first.appearance) %>%
summarise_all(~ first(.[!is.na(.)]))
# a b c d
#1 11 23 31 45
上方
test.df %>%
summarise_all(~ min(na.omit(.)))
# a b c d
#1 11 23 31 45