在特殊情况下禁止禁用(CSRF cookie未设置)

时间:2016-08-14 07:17:34

标签: django pandas matplotlib django-csrf

我有一个post方法,如下所示

    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
    from matplotlib.figure import Figure
    import pandas as pd

    class VisualizeSingleStock(APIView):
        """
        Return the behaviour of the particular stock in all time
        """

        def post(self, request):
            """
             ---
            parameters:
                - name: stock_id
                  description: stock id which behaviour you want to see in all time
                  type: string
                  required: true
            """
            fig = Figure()
            df = pd.DataFrame.from_records(EquityData.objects.filter(stock=str(request.data['stock_id'])).values())
            df = df.set_index(['date'])
            del df['stock']
            del df['id']
            df.plot(subplots=True)
            canvas = FigureCanvas(fig)
            plt.close(fig)
            response = HttpResponse(content_type='image/png')
            canvas.print_png(response)
            return response

这里我从数据库中获取股票,并将日期绘制为x轴,其余列作为y轴,但是当我点击api时,我没有设置CSRF cookie。并且django-rest-swagger在200 OK结果代码中没有显示任何图像。

感谢。

0 个答案:

没有答案