Skip to main content

Django Templates & HTML Rendering (Complete Guide Telugu)

 


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

  1. User URL open chestadu

  2. URL → View ki velthundi

  3. View → Template render chestundi

  4. 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

Popular posts from this blog

“Password Reset in Django – Complete Guide”

  Password Reset in Django – Complete Guide πŸ” Introduction Web applications lo Password Reset feature chala important. User password marchipothe, easy ga recover chesukovadaniki use avutundi. Real-time lo: Gmail Facebook Instagram anni password reset system use chestayi. ⚙️ How Password Reset Works? πŸ‘‰ Step-by-step flow: User “Forgot Password” click chestadu Email enter chestadu System reset link send chestundi User link open chestadu New password set chestadu πŸ‘‰ Idi secure ga untundi because: Token based verification Time limit untundi ⚙️ Django Password Reset Code 1️⃣ settings.py (EMAIL Setup) # settings.py EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' πŸ‘‰ Dev lo console lo email link chupistundi πŸ‘‰ Production lo Gmail SMTP use cheyachu 2️⃣ urls.py from django . urls import path from django . contrib . auth import views as auth_views urlpatterns = [ path ( 'password-reset/' , auth_v...

Python Day 5 – If Else Conditions

  🐍 Python Day 5 – If Else Conditions 🧠 Introduction 🐍 Python Day 5 – If Else Conditions Ippati varaku manam operators nerchukunnam. I roju manam decision making (If-Else) nerchukundam. πŸ‘‰ Program lo condition base chesi decisions tiskovadaniki use avutundi πŸ’‘ Example: Age 18 kanna ekkuva unte → eligible Lekapothe → not eligible πŸ”Ή Basic If Condition age = 20 if age > 18 : print ( "Eligible" ) πŸ”Ή If-Else Condition age = 16 if age >= 18 : print ( "Eligible" ) else : print ( "Not Eligible" ) πŸ”Ή If-Elif-Else marks = 75 if marks >= 90 : print ( "Grade A" ) elif marks >= 60 : print ( "Grade B" ) else : print ( "Grade C" ) πŸ§ͺ Real Example (User Input) age = int ( input ( "Enter your age: " )) if age >= 18 : print ( "You can vote ✅" ) else : print ( "You cannot vote ❌" ) ⚠️ Important Points πŸ‘‰ Indentation (space) very import...

Python Day 8 – Lists

  🧠 Introduction 🐍 Python Day 8 – Lists Ippati varaku manam functions nerchukunnam. Eroju manam Lists gurinchi nerchukundam. πŸ‘‰ List ante multiple values ni okesari store cheyadaniki use avutundi πŸ’‘ Example: Shopping items list laga πŸ“¦ πŸ”Ή Create List numbers = [ 1 , 2 , 3 , 4 , 5 ] names = [ "Manju" , "Ravi" , "Kiran" ] πŸ”Ή Access List (Index) print ( numbers [ 0 ]) # 1 print ( names [ 1 ]) # Ravi πŸ‘‰ Index always 0 nundi start avutundi ⚠️ πŸ”Ή Add Elements numbers . append( 6 ) print ( numbers ) πŸ”Ή Remove Elements numbers . remove( 3 ) print ( numbers ) πŸ”Ή Loop Through List for i in numbers : print ( i ) πŸ”Ή List Length print ( len ( numbers )) πŸ”Ή Slicing print ( numbers [ 1 : 4 ]) πŸ§ͺ Real Example marks = [ 80 , 90 , 75 , 60 ] for m in marks : if m >= 75 : print ( "Pass:" , m ) 🎯 Mini Practice names = [ "A" , "B" , "C" ] names . append( "D...