首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >django blogs.html文件错误中的正则表达式

django blogs.html文件错误中的正则表达式
EN

Stack Overflow用户
提问于 2017-12-13 19:14:50
回答 1查看 20关注 0票数 0

是否有人在以下代码中出现错误:

代码:(在blog.html文件中,即在博客应用程序中)

代码语言:javascript
运行
复制
1   {% extends "aboutme/header.html" %}
2   
3   {%block content %}
4       {% for post in object_list %}
5           <h5>{{post.date|date:Y-m-d"}}<a href="/blog/{{post.id}}">{{post.title}}</a></h5>
6       {% end for %}
7   {% endblock %}

运行错误: http://127.0.0.1:8000/blog/

代码语言:javascript
运行
复制
TemplateSyntaxError at /blog/
Could not parse the remainder: '-m-d"' from 'post.date|date:Y-m-d"'
Request Method: GET
Request URL:    http://127.0.0.1:8000/blog/
Django Version: 2.0
Exception Type: TemplateSyntaxError
Exception Value:    
Could not parse the remainder: '-m-d"' from 'post.date|date:Y-m-d"'
Exception Location: C:\Python34\lib\site-packages\django\template\base.py in __init__, line 668
Python Executable:  C:\Python34\python.exe
Python Version: 3.4.3
Python Path:    
['C:\\Users\\User\\Desktop\\pythonsite\\mysite',
 'C:\\windows\\SYSTEM32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\Python34\\lib\\site-packages']
Server time:    Wed, 13 Dec 2017 19:13:00 +0000
Error during template rendering

In template C:\Users\User\Desktop\pythonsite\mysite\blog\templates\blog\blog.html, error at line 5
Could not parse the remainder: '-m-d"' from 'post.date|date:Y-m-d"'
1   {% extends "aboutme/header.html" %}
2   
3   {%block content %}
4       {% for post in object_list %}
5           <h5>{{post.date|date:Y-m-d"}}<a href="/blog/{{post.id}}">{{post.title}}</a></h5>
6       {% end for %}
7   {% endblock %}
EN

回答 1

Stack Overflow用户

发布于 2017-12-13 19:32:30

TemplateSyntaxError。在date:"Y-m-d" .so中缺少双引号,当django模板处理器试图解析模板时,它找不到第一个双引号的开头

代码语言:javascript
运行
复制
{% extends "aboutme/header.html" %}
    2   
    3   {%block content %}
    4       {% for post in object_list %}
    5           <h5>{{post.date|date:"Y-m-d"}}<a href="/blog/{{post.id}}">{{post.title}}</a></h5>
    6       {% end for %}
    7   {% endblock %}

因为它显然是错误的

代码语言:javascript
运行
复制
TemplateSyntaxError at /blog/
Could not parse the remainder: '-m-d"' from 'post.date|date:Y-m-d"'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47800567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档