Django include


ULASHISH

Include

include tegi joriy shablon ichiga boshqa shablonni ulash imkonini beradi.

Bu ko‘plab sahifalar uchun bir xil bo‘lgan kontent bloki mavjud bo‘lganda foydali.

Misol

templates/footer.html:

<p>You have reached the bottom of this page, thank you for your time.</p>

templates/template.html:

<h1>Hello</h1>

<p>This page contains a footer in a template.</p>

{% include 'footer.html' %} 
Misolni ishga tushirish »

include tegida o‘zgaruvchilar

with kalit so‘zi yordamida shablonga o‘zgaruvchilar yuborishingiz mumkin.

Ulanadigan (include) faylda o‘zgaruvchilarga {{ variablename }} sintaksisi orqali murojaat qilasiz:

Misol

templates/mymenu.html:

<div>HOME | {{ me }} | ABOUT | FORUM | {{ sponsor }}</div>

templates/template.html:

<!DOCTYPE html>
<html>
<body>

{% include "mymenu.html" with me="TOBIAS" sponsor="W3SCHOOLS" %}

<h1>Welcome</h1>

<p>This is my webpage</p>

</body>
</html> 
Misolni ishga tushirish »



W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!