使用Jekyll时获得“液体异常:液体语法错误”

时间:2018-09-14 02:20:33

标签: ruby jekyll

我在Windows 10上运行 bundle exec jekyll serve --trace 。我收到以下控制台消息:

D:\MyPorfolio\perrot.github.io>bundle exec jekyll serve
Configuration file: D:/MyPorfolio/perrot.github.io/_config.yml
            Source: D:/MyPorfolio/perrot.github.io
       Destination: D:/MyPorfolio/perrot.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
  Liquid Exception: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in 2018-09-14-Rendering a python dict in jinja2.markdown

jekyll 3.7.3 |错误:液体语法错误(第8行):“ for循环”中的语法错误-有效语法:对于[collection]中的[item]

有人知道如何解决该问题吗?预先感谢。

文件 2018-09-14-在jinja2.markdown中呈现python字典的内容是:

---
layout: post
title:  "Rendering a python dict in jinja2"
date:   2018-09-14 00:01:57 +0800
categories: python jinja2
---

    ```python
    url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    ```

1 个答案:

答案 0 :(得分:1)

Liquid尝试处理您的源代码,尤其是jinja2控制标签,因为您需要告诉Liquid避免使用raw标签进行处理:

{% highlight python %}
{% raw %}
   url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}

{% endraw %}
{% endhighlight %}