Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django error: could not parse the remainder: ': "Y-m-d"' from 'post.date|date: "Y-m-d"'

Tags:

django

I'm creating a blog post and after migrating my blog files successfully I am returned an error when I go to the blog page of my website ( Could not parse the remainder: ': "Y-m-d"' from 'post.date|date: "Y-m-d"')

I cant seem to find whether this is a syntax error or a logic error

HTML:

{% extends "personal/header.html" %}

{% block content %}

    {% for post in object_list %}

    <h5> {{ post.date|date: "Y-m-d"}} <a href="/blog/{{ post.id }}"> {{ post.title }} </a> </h5>

    {% endfor %}

{% endblock %}

Python (models.py):

from django.db import models

class Post (models.Model):
    title = models.CharField(max_length=140)
    body = models.TextField()
    date = models.DateTimeField()

    def __unicode__(self):
        return self.title
like image 904
Chris Avatar asked Jun 15 '17 15:06

Chris


2 Answers

You need to remove the space after the colon:

{{ post.date|date:"Y-m-d" }}
like image 117
Daniel Roseman Avatar answered Nov 19 '22 04:11

Daniel Roseman


there should be no space between colon (:) and date and date format eg. date:"d-m-Y"

like image 2
vins Avatar answered Nov 19 '22 06:11

vins