0

I am working on a django application. In the application I am trying to display a pandas dataframe in a django template. I am loading a csv file as follows.

df = pd.read_csv(os.path.join(path, str(request.FILES['file'])))
table_content = df.to_html()
context = {'table_content': table_content}
return render(request, 'index.html', context)

The problem I am facing is when I try to display the table. In the template I am retrieving the dataframe as {{table_content}}. But this just displays the html code for the table and not the table itself. I can do a HttpResponse to display the table, but then the rest of the content in the template disappears and only the table is displayed.

What am I doing wrong?

1 Answer 1

3

You can use autoescape (https://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape)

{% autoescape off %}{{ table_content }}{% endautoescape %}
Sign up to request clarification or add additional context in comments.

1 Comment

This will work. You can also use {{ table_content|safe }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.