Django Static Files

Django Static Files

So far we have not seen any Cascading Style Sheets, JavaScript code, or Image files in our simple Django app. These types of files are referred to as static files. These types of files don’t typically change, therefore we refer to them as static. The templates that we have been working with do change since there is logic inside of them and they output data conditionally based on that logic.…

Django Block Content

Django Block Content

Block Content in Django is the concept of working with Template Inheritance. As you add more templates to your project, you will notice that a lot of the markup is duplicated. Every template will have an opening <HTML> tag, an opening <head> tag, a closing </head> tag, a closing </HTML> tag and so on and so forth. The general structure of the HTML document stays fairly consistent, while the content inside the structure may change.…

How To Use Django Tags

How To Use Tags Django

Tags are a key component of Django Templates and they make it possible to embed simple logic into Django templates during the rendering process. This is important because it is not possible to use raw Python in an HTML template since Python runs on the server and not in a Web Browser. Tags bridge this divide and facilitate the ability to output content, act as a control structure, enable if/else logic, and provide looping functionality over dynamic data passed to a template.…

Django Template Filters

Django Template Filters

As we saw in the interpolation tutorial, we are able to output dynamic data in Django Templates using variables the are enclosed in the special opening {{ and closing }} curly brace characters. Django also offers a way to perform various types of data formatting right in the template by use of filters. Filters are like simple built-in functions that you can call using a special pipe | syntax.…

Django Template Language Variables

Django Template Language Variables

The Django Template Language is a special syntax for use inside of HTML files to be used by the Django Web Framework. DTL is an enhanced form of HTML that makes use of standard HTML syntax combined with the Django Specific template language so that variable data can be dynamically injected into the template creating a dynamic HTML page. This page is then returned with the HttpResponse to the client for display in the browser.…

Django render() Function

Django render() Function

Django has a plethora of so-called shortcut functions that make developing with Django easier. These shortcuts are helper functions that span many different levels of the model, view, template paradigm. The render() function is one such function. The purpose of render() is to return an HttpResponse whose content is filled with the result of calling render_to_string() with the passed arguments. We saw how to use the render_to_string() function in the Register Django Templates tutorial.…