Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Template syntax error. Could not parse the remainder (Django)

Asked by Augustina Fuentes Jul 19, 2021 6.8K views 1 answer
Share

About this question

 Can someone point me to the right direction? Below is what I have been doing

    

{{article.snippet}}


    

{{article.date}}


    

{{article.retrieve_by_category("web")}}

I have no problems getting the date or the snippet but I keep getting the following error when trying to run article.retireve_by_category.

Could not parse the remainder: '("web")' from 'article.retrieve_by_category("web")'

Below is the code for the model:

class Article(models.Model):
    category = models.CharField(max_length=100)
    title = models.CharField(max_length=100)
    slug = models.SlugField()
    body = models.TextField()
    date = models.DateTimeField(auto_now_add=True)
    #add in thumbnail
    def __str__(self):
        return self.title
    def snippet(self):
        return self.body[:500] + "..."
    def retrieve_by_category(self,category):
        """retrieves blogs based on their category"""
        if (str(self.category) == category):
            return self.category
        return ''

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.