覆盖get_context_data()在子视图中不起作用

时间:2019-03-09 13:15:24

标签: python django django-class-based-views

我正在尝试在基于子类的视图中覆盖get_context_data(),以向模板发送更多上下文数据,但是它不起作用。作为示例,我正在发送一个测试变量,但该变量未在模板中呈现。

class ProductList(LoginRequiredMixin, View):
   template_name = 'product/product_scroll.html'
   def get(self, request, *args, **kwargs):
        #...
        return render(request, self.template_name, data)  

class Feed(ProductList):
    template_name = "product/feed.html"
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['test'] = 'sometestinfo'
        return context

但是在模板中:

 <p> Prueba: {{test}} </p>

为空。

1 个答案:

答案 0 :(得分:1)

它不起作用,因为您覆盖了TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object at validateString (internal/validators.js:125:11) at normalizeSpawnArguments (child_process.js:414:3) at Object.spawn (child_process.js:553:16) at new FfmpegProcess (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\prism-media\src\transcoders\ffmpeg\FfmpegProcess.js:14:33) at FfmpegTranscoder.transcode (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:34:18) at MediaTranscoder.transcode (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\prism-media\src\transcoders\MediaTranscoder.js:27:31) at Prism.transcode (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\prism-media\src\Prism.js:13:28) at AudioPlayer.playUnknownStream (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:97:35) at VoiceConnection.playFile (C:\Users\hh-hh\Desktop\NODES\DiscordBot\node_modules\discord.js\src\client\voice\VoiceConnection.js:448:24) at message.member.voiceChannel.join.then.connection (C:\Users\hh-hh\Desktop\NODES\DiscordBot\testbot.js:14:41) 。因此,将忽略视图的整个内置功能-包括调用get。您几乎不需要定义get或post方法。