这是我解决它的方法。这是我在 Django 项目中使用的更新版本。
<script src="{% static 'ace/src-noconflict/ace.js' %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static 'ace/src-noconflict/ext-modelist.js' %}"></script>
<script src="{% static 'ace/src-noconflict/ext-language_tools.js' %}"></script>
<script>
var modelist = ace.require("ace/ext/modelist");
var editor = ace.edit("editor");
editor.renderer.setScrollMargin(40, 150)
document.getElementById('editor').style.fontSize = '15px';
editor.setTheme("ace/theme/dracula");
var full_path = "{{ file.directory_path }}";
document.getElementById("demo").innerHTML = full_path
var mode = modelist.getModeForPath(full_path);//mode
console.log(mode);
editor.session.setMode(mode.mode);
//Ace editor autocompletion
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
</script>