它看起来像一个愚蠢的错误,但我没有看到它((我在模板中看不到 my_error 值。
这是我的意见.py
def tasks(request, my_error=''):
print my_error.encode('utf8')
user = request.user.username
try:
fio = Worker.objects.get(login=user)
except Worker.DoesNotExist:
fio = 'Нет такого пользователя'
if user not in admins:
tasks = Task.objects.filter(worker=fio)
else:
tasks = Task.objects.filter()
# here I can still see value of my_error
print my_error.encode('utf8')
return render_to_response('tasks.html',{'user':user,'fio':fio,'tasks':tasks, 'my_error':my_error})
我的模板:
{% extends "base.html" %}
{% block title %}
Список тикетов
{% endblock %}
{% block style %}
<meta http-equiv="refresh" content="60">
{% endblock %}
{% block content %}
Привет, {{ fio.fio }}
<br />
{# {% if my_error %} #}
<h1>{{my_error}}</h1>
{# {% endif %} #}
<ol>
{% for task in tasks %}
<li><a href="../task/{{task.id}}">{{task.name}}<a></li>
{% endfor %}
</ol>
<a href="/new_ticket/">Добавить задачу</a> <br />
{% endblock %}
这里我用 my_error 调用 tasks():
tasks(request, my_error=u'Такой задачи нет. Возможно она была уже удалена')
但是,如果我使用
return render_to_response('tasks.html',{'user':user,'fio':fio,'tasks':tasks, 'my_error':'my_error'})
我在 html 中看到