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

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
主站蜘蛛池模板: 怀安县| 北流市| 永胜县| 昭觉县| 社旗县| 扎鲁特旗| 五家渠市| 樟树市| 特克斯县| 营口市| 武穴市| 江口县| 博乐市| 乌拉特中旗| 苗栗市| 金湖县| 分宜县| 巴中市| 石林| 阿城市| 永定县| 淄博市| 安达市| 门源| 寿光市| 临汾市| 白沙| 德格县| 高淳县| 彭山县| 临朐县| 英吉沙县| 新源县| 遂平县| 惠安县| 星座| 大新县| 阳新县| 喀喇| 临西县| 韶山市|