Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

javascript - How to control selection of items in Django's QuerySet in html template?

I need 2 buttons that would control which item from QuerySet should be displayed as a part of a video player to change playlist videos back and forth (all other features are done and good).

In views.py I have function that sends QuerySet through "video.objects.all()" and I can select any item in HTML template by calling like "videos.all.1.video.url". But IDs are hardcoded and for loop doesn't seem to be fitting here. So I'm stuck on how and where to control items by IDs. Should be html (java?) or in Django's views.py?

Some pointing in the right direction would help.

views.py:

@login_required
def userfunc(request):

    videos = Video.objects.all()
    
    return render(request, 'myapp/myhtml.html', {'videos':videos})

myhtml.html:

<div class="player">

  <video class="player__video viewer" src="{{ videos.all.1.video.url }}"></video>

  <div class="player__central">
    <center>
    <button class="player__button toggle" title="Play">?</button>
    </center>
  </div>

  <div class="player__controls">
    <button class="player__button previous_vid">??</button>
    <button class="player__button next_vid">??</button>
  </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...