このコードを使用して月を印刷していました。views.pyで
currentMonth = datetime.now().month return render_to_response('showroom.html',{'currentMonth':currentMonth,} , context_instance=RequestContext(request))
その後、変数{{ currentMonth }}をファイルに出力します。 12と表示されていますが、12月を表示したいです。
このコードを使用して月を印刷していました。views.pyで
currentMonth = datetime.now().month return render_to_response('showroom.html',{'currentMonth':currentMonth,} , context_instance=RequestContext(request))
その後、変数{{ currentMonth }}をファイルに出力します。 12と表示されていますが、12月を表示したいです。
次のようなものが必要です。
# 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'
>>>