0

It's look like a stupid error, but I don't see it(( I can't see my_error value in template.

Here is my views.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})

My template:

{% 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 %}

Here I call tasks() with my_error:

tasks(request, my_error=u'Такой задачи нет. Возможно она была уже удалена')

But, if I use

return render_to_response('tasks.html',{'user':user,'fio':fio,'tasks':tasks, 'my_error':'my_error'})

I see in html

my_error

. What's wrong?
Ishayahu
  • 349
  • 1
  • 19

1 Answers1

1
except Task.DoesNotExist:
    print 'here'
    tasks(request, my_error=u'Такой задачи нет. Возможно она была уже удалена')

should be

except Task.DoesNotExist:
    print 'here'
    return tasks(request, my_error=u'Такой задачи нет. Возможно она была уже удалена')

ps: paste the significant part of your code in the initial post, so other people may actually know what's going on here withoud digging in comments (aka: paste the bit of view where tasks() is called)

Samuele Mattiuzzo
  • 10,760
  • 5
  • 39
  • 63
  • hey, that's what I'm talking about! If I use my_error I don't see anything, but if I'm passing a string - I can see it. See my code! In views.py I'm passing an variable... – Ishayahu Oct 25 '12 at 13:51
  • aw sorry, didn't understand it completely... can you show more code around the correct call of task? maybe from inside task you're returning with render_to_response, which returns an httpresponse, but where's that task() called? you have to return the value returned by tasks() – Samuele Mattiuzzo Oct 25 '12 at 13:58
  • 1
    loooot of code, but actually i seem to be right... you call the tasks() method, but actually you return something else.. updating my post asap :) – Samuele Mattiuzzo Oct 25 '12 at 14:36
  • just one more qustion: by your code I see page with url http://192.168.1.157:8080/task/25/ Can I change that url to http://192.168.1.157:8080/tasks/ ? I.e. make a redirection and pass a my_error value? – Ishayahu Oct 26 '12 at 06:18
  • that's where your django app is, you have to use apache/nginx in production environement (see the docs) – Samuele Mattiuzzo Oct 26 '12 at 06:20