0

このコードを使用して月を印刷していました。views.py

currentMonth = datetime.now().month return render_to_response('showroom.html',{'currentMonth':currentMonth,} , context_instance=RequestContext(request))

その後、変数{{ currentMonth }}をファイルに出力します。 12と表示されていますが、12月を表示したいです。

4

1 に答える 1

1

次のようなものが必要です。

# Near the top of views.py
from datetime import datetime

# ...
currentMonth = datetime.now().strftime('%B')
return render_to_response('showroom.html',{'currentMonth':currentMonth,} , context_instance=RequestContext(request))

上記のコメントにあるコードでは:

import datetime
currentMonth = datetime.now().month
currentMonthn = currentMonth.strftime("%B")

currentMonthは整数で、strftimeメソッドはありませんが、次datetime.now()のことを行うオブジェクトを返します。

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.now().strftime('%B')
'December'
>>>
于 2012-12-13T09:55:10.563 に答える