请问为什么我会收到以下错误:
Caught NameError while rendering: global name 'name' is not defined.
最初我没有收到这种错误,它刚刚浮出水面 突然。我将我的应用程序恢复到一切正常的状态 我仍然得到同样的错误。
完整堆栈跟踪:
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
模板追溯中的更多细节
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">
在我的模板文件中:
{% 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 %}
当我从我的模板中删除上面的代码时,错误就消失了 表格行不会显示。
来自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})
请提出任何建议。
由于