{django-tables} Caught NameError while rendering: global name 'name' is not defined
Please why am I get the following error:
Caught NameError while rendering: global name 'name' is not defined.
Initially I did not receive this sort of error, it just surfaced all off a sudden. I restored my app to the state where everything worked and I'm still getting the same error.
Full stack trace:
Caught NameError while rendering: global name 'name' is not defined
Request Method: GET
Request URL: http://site/reports
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
Caught NameError while rendering: global name 'name' is not defined
Exception Location: build\bdist.win32\egg\django_tables\models.py in
_default_render, line 73
Python Executable: C:\path\apache\apache2.2.10\bin\httpd.exe
Python Version: 2.7.1
Further details in the template trace back
Template error
In template c:\path\to\project\templates\webapp\reports.html, error at line 41
Caught NameError while rendering: global name 'name' is not defined
31 {% for column in table.columns %}
32 <th {% if forloop.first %} class="first" {% endif %} {% if forloop.last %} class="last" {% endif %} class="table-header">
33 {% if column.sortable %}
34 <a href="?sort={{ column.name_toggled }}">
35 {{ column }}
36 </a>
37 {% endif %}
38 </th>
39 {% endfor %}
40 </tr>
41 {% for row in table.rows %}
42 <tr class="{% cycle 'odd' 'even' %}">
43 {% for value in row %}
44 <td class="table-data">{{ value }}<td>
45 {% endfor %}
46 </tr>
47 {% endfor %}
48 </tbody>
49 </table>
50 <div class="actions-bar wat-cf">
51
<div class="actions">
In my template file:
{% load humanize %}
{% load tables %}
{% load pagination_tags %}
{% autopaginate rows 2 %}
{% for row in table.rows %}
<tr class="{% cycle 'odd' 'even' %}">
{% for value in row %}
<td class="table-data">{{ value }}<td>
{% endfor %}
</tr>
{% endfor %}
When i remove the above code from开发者_如何学运维 my template the error goes away but table rows are not displayed.
code from views.py
class TransactionReport(tables.ModelTable):
identifier = tables.Column(sortable=False, visible=False)
created = tables.Column(sortable=True, visible=True)
@classmethod
def get_reports_paid(self, object, req):
return TransactionReport(object, order_by=req)
class Meta:
model = Transaction
@login_required
def display_reports(request):
logger = logging.getLogger(__name__)
dataqs = Transaction.objects.filter(paid="TRUE")
req = request.GET.get('sort', 'created')
tx = TransactionReport().get_reports_paid(dataqs, req)
return render_to_response('webapp/reports.html', {'table': tx, 'rows' : tx.rows})
Any suggestions please.
Thanks
精彩评论