I am using flask for building a dynamic website thats get its info from python dictionary.
I've made a dictionary for home page articles:
def homePageArticles():
homepage_articles = [
{
'id': 1,
'article_classes': 'img-R-art centerCloud-art BGcolored',
'headline': 'Title 1',
'art_text':'Hi there',
'img_url': 'photo-1.png',
'art_button_text': 'Go',
'art_button_link': 'https://google.com',
'art_button_classes': 'artPrimLink-curved artPrimLink-burder',
'srtucture': """
<h2 class="h1"> ['headline'] </h2>
<p> ['art_text']</p>
<a href="['art_button_link'] " class=" ['art_button_classes'] "> ['art_button_text'] </a>
"""
},
]
return homepage_articles
The whole thing is that I'm trying to call an item from dictionary (e.g: 'headline': 'Title 1'
) inside another item in same dictionary (e.g: 'srtucture': '<h2 class="h1"> ['headline'] </h2>'
to get this result after print:
'id': 1,
'article_classes': 'img-R-art centerCloud-art BGcolored',
'headline': 'Title 1',
'art_text':'Hi there',
'img_url': 'photo-1.png',
'art_button_text': 'Go',
'art_button_link': 'https://google.com',
'art_button_classes': 'artPrimLink-curved artPrimLink-burder',
'srtucture': """
<h2 class="h1"> Title 1 </h2>
<p> Hi there </p>
<a href="https://google.com " class=" artPrimLink-curved artPrimLink-burder "> Go </a>
Ok, I've tried using : <h2 class="h1">{{ article['headline"] }}</h2>
and call it in template with escaping function inside for loop; and it's appear as h2 but its value is: {{ article['headline"] }}. not Title 1 or Title 2.
So I am searching for calling dictionary value inside same dictionary.
If any one has another idea to make what i need to please but it here. thank you
Note: I want to use python dictionary, not sql or any another databases.