user3400457
user3400457

Reputation: 61

Django-Tables2 CSS not working

With the following code, I have been unable to get CSS to work with the tables2 output. I'm using the dev version of tables2 along with Django 1.6, Haystack 2.1 and Python 3.3.

Here are my files:

table.py

import django_tables2 as tables
from bacterial.models import Quorum_Sensing


class QuorumTable(tables.Table):
    class Meta:
        model = Quorum_Sensing
        attrs = {"class": "paleblue"}

report.html

{% load render_table from django_tables2 %}
<!doctype html>
<html>
 <head>
        <link rel="stylesheet"  href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />

    </head>

{% block content %}
<body>
    <h2>Search</h2>

    <form method="get" action="../">
        <table>
            {{ form.as_table }}
            <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" value="Search">
                </td>
            </tr>

        </table>


 {% render_table table %}
        {% if  query %}

            <h3>Results</h3>


        {% else %}

{% endif %}


    </form>


{% endblock %}
 </body>
</html>

views.py

def report(request, template='report.html', load_all=True, form_class=ModelSearchForm, searchqueryset=None, context_class=RequestContext, extra_context=None, results_per_page=None):
    table = QuorumTable(Quorum_Sensing.objects.none())
    query = ''
    results = EmptySearchQuerySet()

    if request.GET.get('q'):
        form = form_class(request.GET, searchqueryset=SearchQuerySet(), load_all=load_all)

        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
            pklist = [r.pk for r in results]
            table = QuorumTable(Quorum_Sensing.objects.filter(pk__in=pklist))
            RequestConfig(request).configure(table)

    else:
        form = form_class(searchqueryset=searchqueryset, load_all=load_all)

    context = {
        'form': form,
        'table': table,
    }

   # return render(request, template, context)
    return render_to_response(template, context, context_instance=context_class(request))

Any help or suggestions would be much appreciated.

Upvotes: 1

Views: 2525

Answers (2)

user3400457
user3400457

Reputation: 61

Thank you for all of the feedback. It turns out I did not have the following code in my settings.py file:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += ('django.core.context_processors.request',)

For anyone else, who runs into this issue make sure you have the above in your settings file.

Thanks again for all of the suggestions.

Upvotes: 1

sandrob
sandrob

Reputation: 258

Did you try to run the command "collect_static": https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic

Upvotes: 0

Related Questions