2

Im trying to convert my tables in my django app to datatables using django-tables2.

Im my campaigns.py view I have:

class CampaignListView(FacebookAdInit):
    """ CampaignListView for viewing all the campaigns"""

    def get(self, request, *args, **kwargs):
        ad_account = self.get_ad_account(kwargs.get('ad_account_id'))

        campaigns = self.get_campaigns(ad_account.get('id')) \
            if ad_account else None
        context = {'campaigns': campaigns, 'ad_account': ad_account}

        return render(request, 'app/campaigns/index.html', context)

Im my campaigns/index.html I have:

{% extends "app/empty_page.html" %}
{% load render_table from django_tables2 %}
{% block content %}
            {% if ad_account %}
                        {% render_table context  %}
            {% endif %}

{% endblock %}

However this gives me the error: Expected table or queryset, not 'str'. ANy help will be greately appreciated.

Right now I generate the table using this piece of code:

                <table class="table table-bordered table-striped" id="campaigns">
                    <thead>
                    <tr>
                        <th> #</th>
                        <th> Campaign Name</th>
                        <th> Campaign Objective</th>
                        <th> Campaign Effective Status</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for campaign in campaigns %}
                        <tr>
                            <td> {{ forloop.counter }} </td>
                            <td>
                                <a href="/ad_accounts/{{ ad_account.id }}/campaigns/{{ campaign.id }}/ad_sets">
                                    {{ campaign.name }} </a>
                            </td>
                            <td> {{ campaign.objective }}</td>
                            <td> {{ campaign.effective_status }} </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
2
  • Post entire traceback please? Commented May 4, 2016 at 20:02
  • Traceback shows what I posted. The error message and the {% render_table context %} line is highlited Commented May 4, 2016 at 20:47

1 Answer 1

1

You should pass a Table instance or queryset to the render_table tag.

{% render_table campaigns %}
Sign up to request clarification or add additional context in comments.

4 Comments

Thats a start. However nothing is generated i.e. I see an empty page ( debug shows no errors)
Sorry, I can't spot any other issues. Your question includes lots of stuff that you haven't show (e.g self.get_campaigns(ad_account.get('id')) so the problem might be somewhere else. Try and get a really simple version working first, like the tutorial does. For example, use Campaign.objects.all()[:10] for the queryset, and don't use any template inheritance until you're sure it's working).
Your code does not show anything that would be trying to access ad_accounts (with an 's'). Your views and templates only contain ad_account.
This seems to be a new question, it isn't related to django-tables2 any more. You've posted lots of code, but you haven't explained what is causing the error or what the error is.

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.