0

Question is related to Jinja2 templating system. But I want to explain the scenario:

According to the doc, App Engine always stores and returns datetime in UTC format. I am using http://code.google.com/p/gae-pytz/ for creating required timezone.

I have TimeProperty in my Model, It is datetime.time object which in turn converted to datetime.datetime object internally.

I am sending list of model instances to jinja2 template system and rendering as shown below:

{% for p in entries %}
    <tr>
        <td>{{ p.time.replace(tzinfo=indian_timezone).strftime("%H:%M:%S") }}</td>
        --- some other fields ---
    </tr>
{% endfor %}

'entries' and 'indian_timezone' is sent from views function, which is actually "indian_timezone=pytz.timezone('Asia/Kolkata')".

We can't render in the way I am doing. So, how do I render 'indian_timezone' inside {{ }} block?

Error I got is: TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'Undefined'.

Thanks in advance..

rajpy
  • 2,436
  • 5
  • 29
  • 43
  • Are you sure `indian_timezone` is actually passed to `render_template()`? Your error indicates that `indian_timezone` name is undefined inside the template. – Audrius Kažukauskas May 16 '13 at 17:20
  • Ya.. I am passing it correctly. I think problem is with jinja2. – rajpy May 17 '13 at 05:39
  • Apologies, there was mistake while sending indian_timezone to template. I won't get error anymore. But time is not changing to IST. How to convert 'datetime.time'(not 'datetime.datetime' object) object from UTC to IST. – rajpy May 17 '13 at 06:51
  • AFAIK, you can't, `datetime.date` objects don't have a notion of timezone. – Audrius Kažukauskas May 17 '13 at 18:22
  • Yeah..I can't do that, I will use 5:30 offset to convert it to Indian timezone. This was another question that I asked regarding UTC to IST conversion. http://stackoverflow.com/questions/16603645/how-to-convert-datetime-time-from-utc-to-different-timezone. Thanks for your help. – rajpy May 18 '13 at 18:57

0 Answers0