Summary of Django framework template language examples [variables, tags, filters, inheritance, html escaping]

The examples in this article describe the Django framework template language. Share it with everyone for your reference, the details are as follows: Template Language The template language is referred to as DTL (Django Template Language) Template variables Template variable names consist of numbers, letters, underscores and dots, and cannot begin with an underscore. Use: {{template variable name}} def index2(request): ”’Template loading order”’ return render(request, ‘booktest/index2.html’) # /temp_var def temp_var(request): ”’Template variable”’ my_dict = {‘title’: ‘Dictionary key value’} my_list = [1, 2, 3] book = BookInfo.objects.get(id=1) #Define template context cOntext={‘my_dict’:my_dict,’my_list’:my_list,’book’:book} return render(request,’booktest/temp_var.html’,context) Template variables can be dictionaries, lists or objects. After defining the template context, use the render() function to pass it to html Use dictionary attributes: {{ my_dict.title }} Using list elements: {{ my_list.1 }} Use object properties: {{ book.btitle }} You can see that template variables are all called through . Template tag {% for book in books %} {% if book.id <= 2 %} {{ forloop.counter }}–{{ book.btitle }} {% elif book.id >= 5 %} {{ forloop.counter }}–{{ book.btitle }} {% else %} {{ forloop.counter }}–{{ book.btitle }} {% endif %} {% endfor %} For specific other template tags, please refer to Django official documentation. Filter Filters…

Encapsulation, inheritance, and polymorphism in Go language

encapsulation The encapsulation in go is different from that in java. There is no class in java in go, but struct can be regarded as a class, and encapsulation can simply be regarded as the encapsulation of struct, as follows type obj1 struct { valte1 string} type obj2 struct { valte2 string} inherit Think of struct as a class. A struct can contain other structs, inherit the methods and variables of the internal struct, and can be rewritten. The code is as follows package mainimport “fmt”type oo struct { inner ss1 string ss2 int ss3 bool}type inner struct { ss4 string}func (i *inner) testMethod(){ fmt.Println(“testMethod is called!!!”)}func main() { oo1 := new(oo) fmt.Println(“ss4 has no value:”+oo1.ss4) oo1.ss4 = “abc” fmt.Println(“ss4 has been assigned”+oo1.ss4) oo1.testMethod()//Inherited call oo1.inner.testMethod()//Inherited call can also be rewritten here} Polymorphic Polymorphism in Go is much more hidden than Java. Strictly speaking, there is no polymorphism, but it can be done using interfaces. For two objects that both implement the same interface, similar upward transformation can be performed, and at this time Methods can be polymorphically routed and distributed. The complete code is as follows package mainimport “fmt”type interfacetest interface { //testMothod1() string //testMothod() //This kind of syntax…

GO learning path (structure, interface, inheritance, serialization)

I used to write JAVA. I used JAVA during the four years of college from my sophomore to my senior year. Now for some reasons, I need to learn GO, so I started I created a new column to record some of my experiences in converting JAVA to GO. My writing is not good and I have little experience in writing blogs. My expression may not be particularly clear. If there are any errors in the article, I hope you guys can point them out. Article Table of Contents Structure Declaration of structure Defining methods of structures Interfaces Declaration of interfaces Implementation of inheritance in Go (embedding) Serialization Structure Although GO is also a The language of objects, but unlike JAVA and C, there is no Class keyword in GO, but struct is used instead. Some differences between struct and class are listed below. Declaration of structure h2> Use type Name struct{} to declare a structure in GO, as follows type Dog struct{ name string} The above code defines a Dog structure, which contains a name field. The type of name is string. The definition of variables in the go language is quite special. Using variable name type to declare…

Can template inheritance be written in html language? Summary of examples of Django framework template language [variables, tags, filters, inheritance, html escaping]…

The examples in this article describe the Django framework template language. Share it with everyone for your reference,The details are as follows: Template Language The template language is referred to as DTL (Django Template Language) Template Variables Template variable names consist of numbers ,letters,underscores and dots,cannot begin with an underscore. Use :{{template variable name}} def index2(request): ''&#39 ;Template loading order''' return render(request, 'booktest/index2.html') # / temp_var def temp_var(request): '''Template variable''' my_dict = {'title': 'Dictionary key value'} my_list = [1, 2, 3] book = BookInfo.objects.get(id=1) #Define template context context={&#39 ;my_dict':my_dict,'my_list':my_list,'book':book} return render(request,'booktest/temp_var. html',context) Template variables can be dictionary, list or object. After defining the template context,Use the render() function to pass it to html Template variables Use dictionary attributes:{{ my_dict.title }} Use list elements :{{ my_list.1 }} Using the object attribute :{{ book.btitle }} you can see that the template variables are all called through. . Template tag Template tag .red{ background-color: red; } . yellow{ background-color: yellow; } .green{ background-color: green; } {% for book in books %} {% if book.id <= 2 %} {{ forloop.counter } }–{{ book.btitle }} {% elif book.id >= 5 %} {{ forloop.counter }}–{{ book.btitle }} {% else %} {{ forloop.counter }}–{{ book.btitle }} {%…

$Django template layer (template import, inheritance), single table * details (add, delete, modify, query based on double underscore), static static file configuration

0Use the django environment in python scripts import osif __name__ == ‘__main__’: os.environ.setdefault(” DJANGO_SETTINGS_MODULE”, “untitled15.settings”) import django django.setup() from app01 import modelsmodels.Book.objects.filter(name=’123′) 1 Template import–>Template reuse 1 Write a template 2 Import in another template:{% include ‘template.html’%} 2 Template inheritance (equivalent to __init__) 1 Write a master and leave an expandable area (box). You can leave multiple Boxes (the more boxes you leave, the higher the scalability) {%block Name%} Yes Write content {%endblock%} {% include ‘left.html’ %} {% block c1 %} wwww {% endblock c1 %} 2 Used in child template: {% extend ‘master.html’%} {%block Name%} {{block.super}} #The content of the master box can be inherited {{block.super}} #The content of the master box can be inherited The content of the child template {%endblock Name% } {% extends ‘1.html’ %}{# inheritance#}{# {{ block.super }} {# invalid#}{#123321312312412412512 {# invalid#}{ % block c1 %} {# Equivalent to the subclass definition __init__. If it is not defined, use the parent class. If it is defined, use your own #} {{ block.super }} {{ block.super }} Hehe Hehe{% endblock c1 %} 3 Static file related 1 Hard-coded static files: /static/css/mycss.css“> 2 Use the static tag function: –{%load static%} #load is a static.py file #static return…

javascript object-oriented, implement namespace, class, inheritance, overloading_js object-oriented

Since most of the client-side work such as Javascript and CSS in the group was handled by another colleague, and that colleague was too busy to refactor, the boss only made suggestions and did not immediately implement the refactoring. But I also fixed some small bugs in the client a few days ago. The code is indeed a bit confusing. I don’t know where I am, and I don’t dare to touch the code easily, so I tinkered with it myself. I once loved and hated it. Javascript, write a simple js to implement namespace, inheritance, overloading and other object-oriented features. Welcome to contribute . Define namespace Namesapce.js The code is as follows: Namespace = new Object(); Namespace.register = function(fullname){ try { var nsArray = fullname.split(“.”); var strNS = “”; var strEval = “”; for(var i=0;i<nsArray.length;i++){ if(strNS.length >0) strNS += “.”; strNS += nsArray[i]; strEval += ” if(typeof(“+ strNS +”) ==’undefined’) ” + strNS + ” = new Object(); “; } if(strEval != “”) eval (strEval); }catch(e){alert(e.message);} } .Employee.js Employee.js The code is as follows: //Register namespaceNamespace.register(“MyCompany”); //1. Class: EmployeeMyCompany.Employee = function(empName){ this.Name = empName; this.Salary = 1000; this.Position = “cleaner”; } MyCompany.Employee.prototype.ShowName = function(){ return “I’m “+this.Name+”,my salary is…

java type conversion and rewriting_java notes encapsulation, inheritance, rewriting, polymorphism and type conversion

java type conversion and rewriting_java notes encapsulation, inheritance, rewriting, polymorphism and type conversion

Foreword Today, let’s talk about the main specific manifestations of object-oriented in Java, namely encapsulation, inheritance and polymorphism. This is the point of the basics. Text Encapsulation Hide implementation details 1) Encapsulation steps: 1 )) Privatize properties , Use the private modifier, to modify the methods and properties that need to be hidden 2)) Provide common methods, to access private properties (getter, setter ) Note: The purpose of encapsulation is to reduce the correlation between classes 2) Encapsulation specifications: 1)) Modify the visibility of the attribute to restrict access to the attribute 2)) Create a pair of assignment and value methods for each attribute 3)) Add restrictions on attributes in the setter and getter methods 3) Benefits of encapsulation: 1)) Increased data access restrictions, Enhances the security of the program 2)) Provides a series of rules for attributes, thereby protecting the attributes 3)) From a broad perspective Implementation details hidden on )) Overloading has nothing to do with the return value Inheritance Things have the same characteristics and there is an inclusion relationship,One thing has the characteristics of another, And have its own independence. 1) Syntax: extends,The table name of the class being constructed,is derived from an existing class Note…

[Mechanism] JavaScript prototype, prototype chain, inheritance

1. The concept of prototype and prototype chain When js creates an object, such as calling it obj, They will secretly add a reference to him. This reference points to an object, such as yuanxing. This object can provide attribute sharing for the object that refers to it. , for example: yuanxing has an attribute name, which can be accessed by obj.name. This can provide an object for attribute sharing. , is called the prototype of the previous object And the prototype itself is also an object, so it will also have its own prototype. This continues layer by layer until it finally points to null, which forms Prototype chain How is the prototype mechanism of js implemented? 2. Prototype implementation Let’s look at an example first: // code-01let obj = new Object({name:’xiaomin’})console.log(obj.name)console.log(obj.toString())// xiaomin // [object Object] We first create an object obj, which has an attribute name The attribute name was created by us, but when creating obj, the toString attribute was not created for it. Why can obj.toString() be accessed? prototype attribute Let’s first take a look at the Object.prototype attribute We found that there is toString here attributes, so in fact Object.prototype is the prototype of obj.…

Java language encapsulation, inheritance, abstraction, polymorphism, interface

Table of contents Foreword 1. Encapsulation 1.1 Definition of encapsulation 1.2 Access modification Use of symbols 2. Inheritance 2.1 Definition of inheritance 2.2 Methods of inheritance 2.3 Points to note when using inheritance 3. Polymorphism 3.1 Definition of polymorphism 3.2 Dynamic binding 3.3 Method rewriting 3.4 Upward (Downward)Transformation 4. Abstraction 4.1 Overview and definition of abstraction 4.2 Use of abstraction p> 5. Interface 5.1 Meaning of interface 5.2 Definition of interface Summary 😽Personal Homepage: tq02’s Blog_CSDN Blog-C Language, Java Blogger 🌈 Ideal goal: study hard and move towards Java There are regrets. 🎁Welcome → Like👍 + Collection⭐ + Comment📝+Follow✨ Contents of this chapter&# xff1a;Java encapsulation, inheritance, abstraction, polymorphism, interface Use compiler :IDEA Preface Before talking about encapsulation, inheritance, abstraction, polymorphism, and interfaces, we must first understand what classes and objects are. Detailed explanation of classes and objects:tq02’s explanation of classes and objects 1 .Package 1.1 Definition of package         Encapsulation ,Operation in the class,Encapsulate the member variables and member methods of the class,Meaning: Can be thought of as a protective barrier,preventing the code and data of this class from being randomly accessed by code defined by external classes. To encapsulate the class we need to use access modifiers, which are…

Javascript is based on the three major characteristics of objects (encapsulation, inheritance, polymorphism)_javascript skills

The three major object-based characteristics of Javascript are the same as the three major object-oriented characteristics of C++ and Java, which are encapsulation, inheritance and polymorphism. It’s just that the implementation methods are different, but the basic concept is almost the same. In fact, in addition to the three major characteristics, there is another common characteristic called abstract, which is why we sometimes see the four major characteristics of object-oriented in some books. 1. Encapsulation Encapsulation is to encapsulate abstracted data and operations on the data together. The data is protected internally, and other parts of the program can only operate on the data through authorized operations (member methods). Case: PS: JS encapsulation has only two states, one is public and the other is private. The difference between adding member methods through constructors and adding member methods through prototype methods 1. Functions allocated through the prototype method are shared by all objects. 2. The attributes assigned through the prototype method are independent. (If you do not modify the attributes, they are shared) 3. It is recommended that if we want all objects to use the same function, it is best to use the prototype method to add the function, which…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索