【问题标题】:tinyMCE HTMLField not showing the results properly in DjangotinyMCE HTMLField 未在 Django 中正确显示结果
【发布时间】:2019-02-19 13:56:47
【问题描述】:

这是我在模板上所做的。

<p class="card-text"> 
{{ profile.about}}    
</p>
<h5>skills:</h5>
<p class="card-text">{{ profile.skills }}</p>
</div>

这是我从 views.py

返回的内容
def about(request):
     profiles = models.profiles.objects.all()
     return render(request,'main/about.html',{'profiles':profiles})

这是我在 models.py 中所做的

#from tinymce.models import HTMLField
about = HTMLField()

一目了然: IMAGE OF A FORM

这就是我展示它时得到的结果。 它不显示富文本,而是显示 html 标签。

the result of tinyMCE

【问题讨论】:

    标签: html django-models django-forms django-templates django-views


    【解决方案1】:

    首先你需要一个表单而不是配置文件对象。

    forms.py

    class ProfileForm(forms.ModelForm):
        class Meta:
            fields = ['skills']
            model = Profile.  # Model names should be CamelCase
    

    views.py

    def about(request, profile_id):
        profile = get_object_or404(Profiles.objects.all(), pk=profile_id)
        form = ProfileForm(instance=profile)
        return render(
            request,
            'main/about.html',
            {'profile':profile, 'form': form}
        )
    

    您还需要为表单使用媒体文件

    main/about.html

    ...
    {{ form.media }}
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-05-11
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多