Django 出现:Could not parse the remainder: 'date::'Y /m /d''

本文介绍了一种在模板语言中正确使用日期格式化的解决方法,通过将双冒号(::)更改为管道符(|),成功地解决了日期显示问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在项目中练习中使用动态Url的时候在日期format的时候出现:

Could not parse the remainder: ‘:date:’Y /m /d” from ‘post.date_time:date:’Y /m /d”

这里主要是自己跟着练习的时候出现疏忽了,原代码是:

{% extends "base.html"%}
{% block content %}
<div class="posts">
    <section class="post">
        <header class="post-header">
            <h2 class="post-title">{{post.title}}</h2>
        <--!主要是这里出现了问题-->
            <p class="post-meta">
                Time: <a class="post-author" href="#">{{post.date_time:date:'Y /m /d'}}</a>
                <a class="post-category-js" href="#">{{post.category}}</a>
            </p>

            <div class="post-description">
                <p>
                    {{post.content}}
                </p>
            </div>
        </header>
    </section>
</div>
{% endblock %}

修改后的代码为:

 <p class="post-meta">
       Time: <a class="post-author" href="#">{{post.date_time|date:'Y /m /d'}}</a>
       <a class="post-category-js" href="#">{{post.category}}</a>
 </p>

主要是把: 改为| 了, 这样子就解决了日期format的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值