官术网_书友最值得收藏!

Chapter 3. Using Templates in Our Headlines Project

In the last chapter, we saw one way of combining static HTML with dynamic content for creating a web page. But it's messy, and we don't want to hack away at Python strings for building our web pages. Mixing HTML and Python is not ideal for a few reasons: for one, it means if we ever want to change static text, such as that which appears in our headings, we have to edit our Python files, which also involves reloading these files into Apache. If we hire frontend developers to work on HTML, we run the risk of them breaking the unfamiliar Python code by mistake, and it's far more difficult to structure any other frontend code such as JavaScript and CSS correctly. Ideally, we should aim for complete segregation between the frontend and backend components. We can achieve this to a large extent using Jinja, but as with most aspects of life, some compromise will be necessary.

By the end of this chapter, we'll have extended our application to display more than a single headline for the chosen publication. We'll display several articles for each publication, each one having a link to the original article, and our logic and view components will largely be separated. In this chapter, we'll cover the following topics:

  • Introducing Jinja
  • Basic use of Jinja templates
  • Advanced use of Jinja templates
主站蜘蛛池模板: 崇义县| 福泉市| 郯城县| 历史| 独山县| 嵊泗县| 恭城| 广安市| 中方县| 昌乐县| 新巴尔虎左旗| 滦平县| 蓝田县| 平度市| 花莲市| 长垣县| 八宿县| 图木舒克市| 德阳市| 平遥县| 汨罗市| 盐源县| 固安县| 扎鲁特旗| 兴国县| 邻水| 普兰店市| 南康市| 上饶市| 梁山县| 崇义县| 长岭县| 通州区| 霸州市| 隆尧县| 泾川县| 龙陵县| 永善县| 咸丰县| 兴宁市| 柳州市|