Formating Django TimeField in a Django view
<p>How do you format a TimeField in a Django view?</p>

<p>Currently in my django html template I can easily do something like: <code>{{movie.start_time|time:"g:iA"|lower}}</code></p>

<p>How can I do the equivalent of the above in a Django view?</p>

<p>Below is an example of how to achieve this. It isn't ideal, but this is what I came up with.</p>

<pre><code>import datetime

now = datetime.datetime.now()
time = now.time()

t = time.strftime("%I:%M %p")
t = t.lower()
t = list(t)

if t[0] == '0':
    t.pop(0)

t = ''.join(t)
print t
</code></pre>

python django