Quick Contact

    Python Tutorial
    Python Panda Tutorial
    Python Selenium
    Python Flask Tutorial
    Python Django
    Interview Questions & Answers

    Django Template Language

    Django templates use special language or syntax to implement it because essentially Django template is nothing but python string, which marks-up by Django Template Engine.

    We will compare our above code and learn the very basics of this syntax.

    There are 4 types of syntax in Django Template language:

    1. Tags/ {% control statements %}

      Whenever we use {% %}, inside a Django Template, we are writing some logic code that will implement on the data we just passed with the render.

      These are called tags in Django Templates.

      In the first template,

      {% for stud in student %}

      We started a for loop which will run until the end of our database records. Then it will repeat the statements above the {% endfor %}. The statements between them can be any segment, either Python or browser renderable (HTML, CSS, JavaScript), etc.

    2. Printing Value/ {{ variables }}

      Whenever we want to print output of Python code in a Django template directly from the server, we use:

      {{variable/ model to print}}

      We will use these statements in most of your browser-renderable code, as this piece here will exchange with the actual value of the variable stored in it by the server.

      Here we have printed 3 variables, as we are accessing the stud object which has all the attributes of student object being passed on.

    3. Filters / {{ metadata | response }}

      Since Django is a web framework, it will also serve content on the basis of metadata, where we use the filters.

      {{ metadata| response or render }}

      We need these filters mostly when working on a very big project, where the metadata for the site matters, otherwise it is not that important for smaller blog websites.

      Although, by using it for metadata, Django also provides us to dynamically generate our metadata.

    4. Comments/ {# Comments #}

      Comments are the best practices that increase code reusability, and readability. Therefore, Django framework provides you with this special tag to comment in the template language.

      The general syntax is:

      {# this will not be rendered by the browser #}

      These are the 4 basic constructs of Django Templates. We will be implementing the same in different ways to make our website look better.



    Apply now for Advanced Python Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.