Book Image

Learn Web Development with Python

By : Fabrizio Romano, Gaston C. Hillar, Arun Ravindran
Book Image

Learn Web Development with Python

By: Fabrizio Romano, Gaston C. Hillar, Arun Ravindran

Overview of this book

If you want to develop complete Python web apps with Django, this Learning Path is for you. It will walk you through Python programming techniques and guide you in implementing them when creating 4 professional Django projects, teaching you how to solve common problems and develop RESTful web services with Django and Python. You will learn how to build a blog application, a social image bookmarking website, an online shop, and an e-learning platform. Learn Web Development with Python will get you started with Python programming techniques, show you how to enhance your applications with AJAX, create RESTful APIs, and set up a production environment for your Django projects. Last but not least, you’ll learn the best practices for creating real-world applications. By the end of this Learning Path, you will have a full understanding of how Django works and how to use it to build web applications from scratch. This Learning Path includes content from the following Packt products: • Learn Python Programming by Fabrizio Romano • Django RESTful Web Services by Gastón C. Hillar • Django Design Patterns and Best Practices by Arun Ravindran
Table of Contents (33 chapters)
Title Page
About Packt
Contributors
Preface
Index

Jinja2


Jinja2 is very similar to DTL in syntax. But it has a slightly different philosophy in certain places. For instance, in DTL the method call is implied as in the following example:

{% for post in user.public_posts %} 
    ... 
{% endfor %} 

But in Jinja2, we invoke the public_posts method similar to a Python function call:

{% for post in user.public_posts() %} 
    ... 
{% endfor %} 

This means that in Jinja2 you can call functions with arguments, unlike DTL. Refer to the Jinja2 documentation for more such subtle differences.

Jinja2 is usually chosen for the following reasons:

  • Familiarity: If your template designers are already comfortable using Jinja2
  • Whitespace control: Jinja2 has finer control over whitespace after the tags get rendered
  • Customizability: Most aspects of Jinja2, from string defining markup to extensions, can be easily configured
  • Performance: Some benchmarks show Jinja2 is faster than Django
  • Autoescape: By default, Jinja2 disables XML/HTML autoescaping for performance

In most...