Django 2.2 Dynamic data pass to view

Pinterest LinkedIn Tumblr

Create a model

class Page():
    id: int
    name: str

Import to View

from .models import Page
def indexPageView(request):
        page = Page() ="home"
        page1 = Page() = "about"

        page2 = Page() = "contact"

        page = [page, page1, page2]
        return render(request, "index.html", {'page': page})

Now add for loop to index.html

 {% for page in page %}
                    <h1>{{ }}</h1>
 {% endfor %}

Write A Comment