2016-08-18 57 views
1

我在Mac上使用带有ESLint的Atom编辑器。我需要删除具有脚本标记的html文件,以便安装eslint-plugin-html和linter-eslint。但是,我的一些html文件中包含django代码,ESLint报告错误。 解析错误。意外的令牌%。请告知ESLint如何忽略此类服务器端代码。这里是我的html文件看起来像Atom ESLint忽略服务器端语言代码

// some html here 
<script> 
    var foo = { 
     {% for item in items %} 
      {% if item == "foo" %} 
      'foo': 'foo' 
      // etc 

回答

1

一些选项:

A.禁止掉毛特定lines, sections of code, or an entire file

B.禁用掉毛为specific file extensions

C.避免其内Django的语法<script>标签。

这样做的一种方法是将数据获取到一个JavaScript变量,然后在JavaScript中操纵它。

views.py

def myview(request): 
    some_django_data = json.dumps(geodata) 
    ... 

template.html

<script> 
    var foo = JSON.parse('{{ some_django_data|safe }}') 
</script> 
<script scr="/path/to/myscript.js"></script> 

myscript.js

foo.forEach(myFunc);