asked    Denise     2018-10-22       python       82 view        2 Answers

[SOLVED] jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted'

I'm new to programming and recently a friend of mine gave me a project to work on in order to get myself familiar with the programming environment and language (python in this particular example). I used this video as a beginners tutorial to help me understand how i'm supposed to proceed with my personal project. the code i wrote is exactly how it is written in the video, and i get an error.

from flask import Flask, render_template
app = Flask(__name__)

posts = [
        'author': 'Alon Salzmann',
        'title': 'First Post',
        'content': 'First post content',
        'date posted': 'September 5, 2018'
        'author': 'Alon Salzmann',
        'title': 'Second Post',
        'content': 'Second post content',
        'date posted': 'September 6, 2018'

def homepage():
    return render_template('Home.html', posts=posts)

def about():
    return render_template('About.html')

if __name__ == '__main__':

The code above is the python code I wrote, and the code below is the html code I wrote that involves python:

<!DOCTYPE html>
    {% for post in posts %}
    <h1>{{ post.title }}</h1>
    <p>By {{ }} on {{ posted }}</p>
    <p>{{ post.content }}</p>
    {% endfor %}

after running the program on both cmd and powershell (not simultaneously of course), and going to my localhost address, i got the error that appears in the title:

"jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'posted'"

I would love to get a good explanation as to why this has been happeninig, and how to fix this. Please remember I am a beginner and maybe need to be explained a few basic concepts at first :).

ps. The guy's code in the video worked so I would love to understand where I went wrong.

  2 Answers  

        answered    Venus     2018-10-22      

The line <p>By {{ }} on {{ posted }}</p> is the issue here

Replace it with <p>By {{ }} on {{ post.date_posted }}</p>

post.date_posted is a variable and should be same as the one in your models, And spaces between them are obviously syntax errors(typos)

        answered    Barnett     2018-10-22      

You have to do <p>By {{ post['author'] }} on {{ post['date posted'] }} to make it work. it is a dict. So you have to get the values with indicies instead of calls.

Your Answer

 2018-10-22         Chester

How do I inject build version into pom.xml using TFS on UI?

I have a TFS build definition that deals with a java spring backend application that is built with Maven. I have a build step called "Maven pom.xml" where I obviously can set some options of the pom.xml. I need to change the "version" tag in the pom.xml using TFS whilst building, so that the "info" endpoint in actuator serves the correct version number including the TFS build number.1) Is this possible using the TFS UI at all? 2) If yes, should I change "Options" textbox content or "MAVEN_OPTS" and how do I feed parameters there, that change <version> in the pom.xml? ...
 java                     2 answers                     63 view
 2018-10-22         Burnell

After logging in I am redirected to /robots.txt

So since a couple of weeks now we have noticed some strange behaviour on a couple of projects that use Spring Boot and Spring Security.Mostly only OSX users seem to have this issue but whenever we login to our application it randomly redirects back to robots.txtI realise that this is probably not enough info, but sadly it's all I got. We have seen this pop up only on OSX so far and on 3 different projects (some live and some running locally)server logs have this as request info (I removed/obfuscated some the real info):Request parameters:Request attributes:javax.servlet.for...
 spring-boot                     1 answers                     64 view
 2018-10-22         Andy

Stanford CoreNLP Server: Reduce memory footprint

I am acessing the CoreNLP Server from a Python script running in Jupyter Lab. I am using the full annotator suite to extract quotes from newspaper articles.request_params={'annotators': "tokenize,ssplit,pos,lemma,ner,depparse,coref,quote",...As against the recommended 2GB, I have allocated 4GB and yet the quote annotator fails to load. Windows task manager shows memory utilization at >94% for long periods. Where can I get a list of options that I can tune to improve memory use? The coreference models are probably the main culprit. If you don't care about quote attribut...
 stanford-nlp                     1 answers                     67 view