为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 html div 中显示 Python print()

如何在 html div 中显示 Python print()

呼如林 2021-06-28 16:55:36
我正在使用 Django 编写我的网站。在编写我的 Python 代码期间,我有许多打印功能。它们都显示在标准控制台中。我想在我的 HTML 代码中的 div 中显示(不刷新页面的实时)我的所有打印,而不仅仅是在控制台中。怎么做?我的代码是:你按下按钮然后 selenium 开始使用 ajax 而不刷新页面,在此期间我想使用 div 在页面上显示进度。例如,我的代码:views.pybot = Instagram()class InstabotFormView(AjaxFormMixin, FormView):    form_class = LoginInstagramForm    template_name = 'instabot.html'    success_url = 'runinstabot.html'    def form_invalid(self, form):        response = super(InstabotFormView, self).form_invalid(form)        if self.request.is_ajax():            return JsonResponse(form.errors, status=400)        else:            return response    def form_valid(self, form):        response = super(InstabotFormView, self).form_valid(form)        login = form.cleaned_data.get('login')        password = form.cleaned_data.get('password')        tagi = form.cleaned_data.get('tags')        func = form.cleaned_data.get('function')        tags = []        tagi = tagi.split(',')        tags.extend(tagi)        if self.request.is_ajax():            print('It is AJAX')            bot.login(login,password)            bot.search(tags)            if func == '1':                bot.downloadPhoto(tags)            elif func == '2':                bot.doCalculation(tags)            print(tags)            data = {                'message': "Succesfully  opened Selenium."            }            return JsonResponse(data)        else:            return responseInstagram()    def downloadPhoto(self):        i = 0        time.sleep(2)        self.driver.find_element_by_xpath('/html/body/span/section/main/div/header/section/ul/li[2]/a').click()        print('Start function downloadPhoto')        print(self.myCurrentList)        for photo in self.myCurrentList:            followerPhoto = self.myCurrentList.index(photo) + 1            print(followerPhoto)如何在 html div 中显示来自 def downloadPhoto(self) 的所有打印件?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 299 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号