Introduction
Previous article lo manam Views & URLs chusam.
Ipudu next important concept 👉 Templates & HTML Rendering
Django lo dynamic HTML pages ela create cheyyalo ee article lo nerchukundam 🔥
🧠 Templates ante enti?
👉 Template ante HTML file
"Template ante HTML file matrame kaadu, Django lo dynamic content ni display cheyadaniki use chestam. Example ga, database lo unna blog posts ni HTML page lo chupinchadaniki templates use avutayi."
But special enti ante:
👉 Dynamic data display cheyyachu (Python data → HTML lo show)
📁 Templates folder create cheyyadam
Mee app lo templates ane folder create cheyandi:
myapp/
templates/
index.html
⚙️ settings.py lo config cheyyali
settings.py open cheyandi:
TEMPLATES = [
{
'DIRS': [],
...
},
]
👉 Usually app templates automatic ga detect chestundi
💻 Simple HTML Template
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Django Page</title>
</head>
<body>
<h1>Hello {{ name }}</h1>
</body>
</html>
👉 {{ name }} → dynamic data placeholder
⚡ View lo render cheyyadam
from django.shortcuts import render
def home(request):
return render(request, 'index.html', {'name': 'Manju'})
👉 Output:
👉 “Hello Manju” page lo kanipisthundi 🎉
🔗 URL connect cheyyadam
from django.urls import path
from .views import home
urlpatterns = [
path('', home),
]
🔄 Flow ardham chesko
User URL open chestadu
URL → View ki velthundi
View → Template render chestundi
Data → HTML lo display avthundi
🔥 Template Tags
Django lo special syntax untundi:
{{ variable }}→ data display{% %}→ logic (loops, conditions)
Example:
{% if name %}
<h1>Hello {{ name }}</h1>
{% endif %}
✅ Conclusion
Meeru ippudu Django lo HTML pages dynamic ga render cheyyadam nerchukunnaru 🎉
🔜 Next Article
👉 Django Static Files (CSS, JS, Images)
Stay tuned 🔥
Comments
Post a Comment