Javascript 如何重定向到其他模板并使用django中从原始模板传递的值提交表单

Javascript 如何重定向到其他模板并使用django中从原始模板传递的值提交表单,javascript,django,django-views,django-templates,Javascript,Django,Django Views,Django Templates,我正在Django创建一个youtube克隆项目,我只停留在其中一部分。我想实现类似youtube的功能,当单击#标记时,它将该标记作为一个值来搜索并呈现包含标记的搜索视频 我已经使用Haystack实现了搜索功能。我可以从主页上搜索视频(比如youtube)。我现在想要的是,当我点击视频播放页面上的标签时,标签值应该出现在我的主页(或视图)上,并且主页模板中的搜索表单应该接受它的值并搜索它(标签的搜索应该与我们从主页手动搜索标签时的搜索完全相同) views.py class HomeView

我正在Django创建一个youtube克隆项目,我只停留在其中一部分。我想实现类似youtube的功能,当单击#标记时,它将该标记作为一个值来搜索并呈现包含标记的搜索视频

我已经使用Haystack实现了搜索功能。我可以从主页上搜索视频(比如youtube)。我现在想要的是,当我点击视频播放页面上的标签时,标签值应该出现在我的主页(或视图)上,并且主页模板中的搜索表单应该接受它的值并搜索它(标签的搜索应该与我们从主页手动搜索标签时的搜索完全相同)

views.py

class HomeView(SearchView):

    template_name = 'core/home.html'
    form_class = SearchForm

    def get_context_data(self, **kwargs):
        context = {}
        context['videos'] = Video.objects.all()
        context.update(kwargs)
        return super().get_context_data(**context)

class VideoView(DetailView, FormView):
    template_name = 'core/video.html'
    form_class = React

    def get_object(self, **kwargs):
        return Video.objects.get(id=self.kwargs['id'])

    def get_context_data(self, **kwargs):
        context = {}
        if self.object:
            context['object'] = self.object
            context['likes'] = self.object.userprofile_set.count()          #likes count by ManyToManyField reverse reference
            context['comments']=self.object.comment_set.all()   #comments by ForeignKey reverse reference

            if self.request.user.is_authenticated:
                if self.object.userprofile_set.filter(id=self.request.user.userprofile.id).exists():
                    context['likestatus'] = True
                else:
                    context['likestatus'] = False

        context.update(kwargs)
        return super().get_context_data(**context)

def get_success_url(self):
    return reverse('core:videoview',kwargs={'id':self.kwargs['id']})

def post(self, request, *args, **kwargs):
    form = self.get_form()
    if form.is_valid():
        print(form.cleaned_data['comment'])
        c_text = form.cleaned_data['comment']
        c_date = datetime.datetime.now()
        c_owner = request.user.userprofile
        c_video = Video.objects.get(id=self.kwargs['id'])

        newComment = Comment(comment_text=c_text,comment_datetime=c_date,
                             comment_owner=c_owner,commented_video=c_video)
        newComment.save()
        return self.form_valid(form)
home.html


{%if查询%}
结果
{%用于页面_obj.object_list%}
{{result.video_title}
{%empty%}

未找到任何结果

{%endfor%} {%else%}