是否有人在以下代码中出现错误:
代码:(在blog.html文件中,即在博客应用程序中)
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/
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 %}发布于 2017-12-13 19:32:30
有TemplateSyntaxError。在date:"Y-m-d" .so中缺少双引号,当django模板处理器试图解析模板时,它找不到第一个双引号的开头
{% 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 %}因为它显然是错误的
TemplateSyntaxError at /blog/
Could not parse the remainder: '-m-d"' from 'post.date|date:Y-m-d"'https://stackoverflow.com/questions/47800567
复制相似问题