将pandas数据帧传递给Django模板

时间:2021-11-28 23:49:00

I am creating a website using Django, bootstrap3 and Dajaxice. I want to pass a pandas dataframe from my views.py to one of my templates but am having trouble getting it to work. I need it as a dataframe and not html so using .to_html() isn't an option.

我正在使用Django,bootstrap3和Dajaxice创建一个网站。我想将我的views.py中的pandas数据帧传递给我的一个模板,但是无法让它工作。我需要它作为数据帧而不是html所以使用.to_html()不是一个选项。

The html:

<div class="text-center">
    <button class="btn btn-primary" type="button" name="UpdateDB" onclick="submitverify({{file_dfs}})">Submit Files {% bootstrap_icon "chevron-right" %}</button> 
</div>

When I try to pass file_dfs I get an Uncaught SyntaxError: Unexpected token ILLEGAL error on {{file_dfs}}. When I open chromes developer tool it looks like this:

当我尝试传递file_dfs时,我得到一个未捕获的SyntaxError:{{file_dfs}}上出现意外的令牌ILLEGAL错误。当我打开chromes开发人员工具时,它看起来像这样:

<button class="btn btn-primary" type="button" name="UpdateDB" onclick="submitverify({&#39;_COMM_&#39;: [], &#39;_CMD_&#39;: [         WINDOW_START ...]})"

Can anyone help me out on this??

任何人都可以帮我解决这个问题吗?

Thanks!

1 个解决方案

#1


1  

Is auto escaping turned on? It appears that Django has it turned on by default (see code.djangoproject.com/wiki/AutoEscaping). If it is turned on, you need to turn it off for the data frame.

是否已开启自动转义功能?似乎Django默认打开它(参见code.djangoproject.com/wiki/AutoEscaping)。如果已打开,则需要为数据框关闭它。

#1


1  

Is auto escaping turned on? It appears that Django has it turned on by default (see code.djangoproject.com/wiki/AutoEscaping). If it is turned on, you need to turn it off for the data frame.

是否已开启自动转义功能?似乎Django默认打开它(参见code.djangoproject.com/wiki/AutoEscaping)。如果已打开,则需要为数据框关闭它。