<html> <head ... Database img name url path Lisa http:// path Bart http:// For each entry in the database ... Templates <html> <head> <title> ... ... create the corresponding HTML entry in the template webdirectory/
WebDirectory.models import Entry def index(request): entry_list = Entry.objects.all() return render(request,\ 'WebDirectory/index.html',\ {'entry_list': entry_list}) Fetch all entries in the database Call the template index.html with the list of all entries as argument
%} {% for entry in entry_list %} {% include "WebDirectory/entry.html" with e=entry %} {% endfor %} {% else %} <p>No entry.</p> {% endif %} </div> include the external template entry.html parameters (the context is passed by default)
{% block content %} <div id="directory"> {% if entry_list %} {% for entry in entry_list %} {% include "WebDirectory/entry.html" with e=entry %} {% endfor %} {% else %} <p>No entry.</p> {% endif %} </div> <div id="publisher">Upload a new entry!</div> {% endblock %} </div> ... Only this part will be different