为此,我正在尝试使用lektor CMS
建立一个博客。。我需要一个标签系统,在搜索之后,我在lektordocs上找到了一个名为lektor-tags
的lektor插件
我遵循文档的每一步,努力了很多,甚至访问了githubrepo,看看文档中是否还有其他未包含的内容
我的问题是,当我试图访问localhost:5000/{the_tag_name}
时,比如说localhost:5000/python
,我总是听到一个404 Not Found
这样说
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
这就是我目前所做的:
在之前使用lektor-tags
:
我将博客帖子的路径改为/posts
,而不是/blog
在[children]
中的models/blog.ini
中添加了slug格式
[children]
model = blog-post
order_by = pub_date, title
slug_format = {{ (this.pub_date|dateformat('YYYY/M/') if this.pub_date) ~ this._id }}
创建了3个帖子,一切正常。
此时我想使用标签系统,所以我选择使用lektor-tags
,我所做的是:
装置
lektor plugins add lektor-tags
使用此配置创建了configs/tags.ini
:
parent = /
url_path = {{ this.parent.url_path }}{{ tag }}
tags_field = tags
ignore_missing = true
template = tags.html
使用以下内容创建了templates/tags.html
:
{% extends "layout.html" %}
{% block title %}{{ this.title }}{% endblock %}
{% block body %}
<div class="container mt-3">
<b>Tag: {{ this.tag }}</b>
<b>Items:</b>
<ul>
{% for i in this.items %}
<li><a href="{{ i|url }}">{{ i._id }}</a></li>
{% else %}
<li><em>No items.</em></li>
{% endfor %}
</ul>
</div>
{% endblock %}
编辑models/blog-post.ini
并添加:
[fields.tags]
type = strings
在templates/blog-post.html
中,我添加了以下内容,以显示指向页面的链接,该页面包含带有特定标记的所有帖子的列表:
{% if this.tags %}
<ul>
{% for t in this.tags -%}
<li>
<a href="{{ ('/' ~ t.lower())|url }}">
All posts tagged {{ t }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
最后我更新了一篇文章,其中包含一些来自管理员的标签,并确保它位于该文章的content.lr
中。因此,我停止了lektor dev服务器并再次运行它lektor servor
,没有出现任何错误
标签的链接在帖子中,但是当我点击并跟随一个链接时,比如说python标签localhost:5000/python
,我得到了404 Not Found
。我是莱克托的新手。我想知道我做错了什么,我怎样才能让它正常工作
NB:我使用的其他插件是lektor-minify
,lektor-disqus-comments
这些插件的文档很简单,我没有感到困惑,但是当谈到这个特定的插件时,我感到困惑,挣扎:文档没有那么好,解释性很强,我觉得完全迷失了方向
我创建了一个github repo包含代码和我到目前为止所做的工作,因此您可以轻松地复制它
我设法使其正常工作,请参见下面的答案,但是现在我想知道如何将根设置为父级,换句话说,如何编辑此表达式:
<a href="{{ ('/posts@tag/' ~ t.lower())|url }}">
为每个博客文章的标记生成源路径,但使用root作为父项。 正如你所看到的,我试过:
<a href="{{ ('/' ~ t.lower())|url }}">
但这不能正常工作
值得一提的是,lektor使用jinja2
模板语言
所以基本上是我做错了,因为我想在
tags.ini
中使用根作为父对象,就像这样:最后,我将
blog-post.html
中的'/blog@tag/' ~ t.lower()
表达式更改为如下内容:使其无法为每个博客文章的标记生成源路径
我改变和工作的是:
我选择
posts
作为父项,将configs/tags.ini
更新为:更新
templates/blog-post.html
:运行
lektor clean yes
之后lekor server
一切正常,包括标签系统相关问题 更多 >
编程相关推荐