我在Mac上使用Atom Editor和ESLint。我需要lint包含脚本标签的html文件,所以我安装了eslint-plugin-html和linter-eslint。但是,我的一些html文件中包含django代码,ESLint报告错误。 解析错误。意外的标记%。请告知ESLint如何忽略此类服务器端代码。这是我的html文件的样子
// some html here
<script>
var foo = {
{% for item in items %}
{% if item == "foo" %}
'foo': 'foo'
// etc
答案 0 :(得分:1)
一些选项:
一个。禁用特定lines, sections of code, or an entire file
的linting 的linting℃。避免在<script>
标记内使用django语法。
实现此目的的一种方法是将数据转换为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);