本文介绍了使用django-froala编辑器,编辑器在管理页面中的作品将不会在页面中工作?未捕获TypeError:$(...)。froalaEditor不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我以前的帖子不清楚,对不起
我使用django-froala-editor,,但它不会工作。我记得在我的最后一个项目中使用这个,但是这次不行。我安装并配置了它,在管理页面中它的工作,但在管理页面之外它将无法工作。我按照文档说{{form.media}},不行。在控制台我得到U $(...)。froalaEditor不是一个功能

 < script> 
$(function(){
$('#id_content')。froalaEditor({imageUploadURL:/ froala_editor / image_upload /,fileUploadParams:{csrfmiddlewaretoken:getCookie(csrftoken ),inlineMode:false,fileUploadURL:/ froala_editor / file_upload /,imageUploadParams:{csrfmiddlewaretoken:getCookie(csrftoken)}})
});
< / script>

我没有写。我有这样的

  {{form | as_bootstrap} 

和我的forms.py

  content = forms.CharField(widget = FroalaEditor)

froala编辑死了吗或者我做错了?

解决方案

如果没有设置getCookie函数,那么可以按照这个页面添加它:

  //使用jQuery 
函数getCookie(name){
var cookieValue =空值;
if(document.cookie&& document.cookie!=''){
var cookies = document.cookie.split(';');
for(var i = 0; i< cookies.length; i ++){
var cookie = jQuery.trim(cookies [i]);
//这个cookie字符串是否以我们想要的名字开头?
if(cookie.substring(0,name.length + 1)==(name +'=')){
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

所以只需将它添加到你的项目中。还要确保包括所有文件。也许你错过了已经添加了此功能的文件。


Sorry if my previous post wasn't clear. I'm using django-froala-editor, https://github.com/froala/django-froala-editor but it just won't work. I remember using this in my last project but this time it won't work. I installed and configured it ,inside admin page it works but outside admin page it won't work. I did as the doc said {{form.media}} and it won't work. In console I get U$(...).froalaEditor is not a function

<script>
            $(function(){
                $('#id_content').froalaEditor({"imageUploadURL": "/froala_editor/image_upload/", "fileUploadParams": {"csrfmiddlewaretoken": getCookie("csrftoken")}, "inlineMode": false, "fileUploadURL": "/froala_editor/file_upload/", "imageUploadParams": {"csrfmiddlewaretoken": getCookie("csrftoken")}})
            });
        </script>

which I didn't write. I have this instead

    {{ form | as_bootstrap }}

and in my forms.py

    content = forms.CharField(widget=FroalaEditor)

Is froala editor dead? or am I doing it wrong?

解决方案

If the getCookie function is not set, then perhaps add it as per this page:https://docs.djangoproject.com/en/1.9/ref/csrf/

// using jQuery
function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}

So just add it to your project. Also make sure you have included all files. Perhaps you are missing a file which already has this function added.

这篇关于使用django-froala编辑器,编辑器在管理页面中的作品将不会在页面中工作?未捕获TypeError:$(...)。froalaEditor不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:11