开发者

Is it possible to prevent a base template reloading using django's template inheritance?

In the header region of my base template (main.html), I've placed an HTML5 media player which pulls in content uploaded through my admin interface.

What I'm attempting to do is, when the tracks have been loaded once, have the media player remain unaffected by internal site navigation. In other words, the media player keeps playing but the user can browse the site without interrupting playback/ re-loading the tracks.

It's a fairly simple setup. There's one main template and each of the other sections (say, blog, contact and about) are all content blocks loaded within that same template using:

{% extends 'main.html' %}

As I understand it, when the template system evaluates a child template, first it loads the parent then fills in the child blocks as defined. I logically, and perhaps incorrectly, assumed that开发者_开发百科 child block regions would be 'pulled into' the parent. However, having read the django docs on template inheritance, it would appear that what actually happens is some sort of reverse lookup: find parent > load parent > find blocks > populate blocks. As I have it set up at the moment, each time a link is clicked, the media stops playing and is reloaded.

So my question is whether I've missed something fundamental in the way the django's template engine works and it is possible to achieve what I'm after just using the template engine, or whether it's impossible and I need to do it some other way (e.g. via AJAX). It's the first time I've attempted to do anything like this in django so I wouldn't be at all surprised if it's the former.


What I'm attempting to do is, when the tracks have been loaded once, have the media player remain unaffected by internal site navigation. In other words, the media player keeps playing but the user can browse the site without interrupting playback/ re-loading the tracks.

This is not something specific to Django-templates, but rather to how your HTML page is structured. The media player is not replaced within Django, but replaced in the browser by reloading the page.

Things you can do:

  • Have everything running via Ajax.
  • Have every other page running in an <iframe>
  • Have every other page running in a <frameset> tag.

Eiter way, the URL in your address bar won't change anymore while the user is navigating through the site. Requiring Ajax will also affect how good Google can index your site.

A good HTML book will get you started on setting up the frameset / iframe based page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜