Need Help With View Query Comparing Dates

The problem with html fragments that get called to make a full page is that these files do not have a published path like other pages. That’s what I’m hung up on. Can I express a specific file in urls.py? I’ve been trying that approach with no luck.

I think you’re still looking at this from the wrong direction.

Templates don’t have “published paths”.

The url sent from the browser causes a view to be called.

The view uses whatever templates it needs to do to build the response.

The template files are never directly mapped or exposed to the browser.

Views create pages.

  • Templates don’t create pages. Templates are used as data to assist with the creation of pages.
  • A view can create a page without ever using a template.

Merry go round here.

So, breaking it down. The view below, which I’ve confirmed works, I want to be available in the file “header.html.” As written, the view is being sent to that template. All that is fine and dandy. The missing piece of the puzzle that I’m not understanding is how to activate that view, which I think can happen in urls.py. Or maybe there is some other way that a newbie hasn’t figured out.

All my pages are built from “base.html” with include calls to incorporate “navigation.html” and “header.html.”

def last_database_update(request):
    last_updated_collection_object = Collection.objects.latest('date_saved')
    last_updated_collector_object = Collector.objects.latest('date_saved')
    if last_updated_collection_object.date_saved > last_updated_collector_object.date_saved:
        last_updated_object = last_updated_collection_object
    else:
        last_updated_object = last_updated_collector_object
    template = 'collections_app/header.html'
    context = {'last_updated_object': last_updated_object}
    return render(request, template, context)

Yes, because until you get your mental model in alignment with how Django actually functions, these types of confusions will continue to occur. This really is a fundamental point with understanding Django.

A view is not “available” in any template. A view does not get sent to a template.