django模版local variable 'has' referenced before assignment

views:
def common_statistic(request):
    '''公共信息
    '''
    ...

    bench_name = query.get('bench_name', '')
    ...


    return render(request, '/backends/qta/statistic-androidqq.html', params)


模版:
...
% if bench_name:
    //some html
% else:
    % for bench_name, data in data_dict.items():
    //some html
    % endfor
% endif

...


 页面提示:
local variable 'bench_name' referenced before assignment
原来是for循环里的bench_name把views里的bench_name覆盖了,导致模版渲染时出现bench_name未赋值先使用的情况,把for循环里的bench_name改成别的变量名就ok了


参考:http://blog.csdn.net/jiangnanandi/article/details/3553243

你可能感兴趣的:(django)