self.publish.strftime('%m')

39 views
Skip to first unread message

林攀

unread,
Jan 26, 2016, 8:56:29 AM1/26/16
to django...@googlegroups.com
return reverse('blog:post_detail', args=[self.publish.year,
self.publish.strftime('%m'),
self.publish.strftime('%d'),
self.slug])
url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>[-\w]+)/$',
views.post_detail, name='post_detail'),

i feel confused why publish.year(type int) don't use strftime method .


--
林攀


可莱丝面膜低至4.5元 /片,限量疯抢中!马上去抢>>

James Schneider

unread,
Jan 26, 2016, 2:08:02 PM1/26/16
to django...@googlegroups.com
publish.year is probably an integer (or a property that returns an integer), not a datetime object, hence it doesn't support the .strftime() method. Without the model/object definition, I couldn't say for sure, though.

You can probably substitute it with self.publish.strftime('%Y') if it makes you feel better.

-James

Peter of the Norse

unread,
Jan 30, 2016, 1:58:24 PM1/30/16
to django...@googlegroups.com
You could use self.public.strftime(‘%Y’) without any problems here.  If fact, it might be a bit safer if the year is ever less then four digits.  Since month and day are exactly two digits in the URL, reverse has to make sure they match exactly.  That means making sure there is a leading zero.  With the year, you don’t have to worry about that, so it gets skipped.
Peter of the Norse



林攀

unread,
Jan 31, 2016, 7:38:07 AM1/31/16
to django...@googlegroups.com
 it works well .thanks .




--
林攀
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9C959670-19AE-48A3-97E7-A8C99E4A8A6B%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


新的一年,让我陪你奋斗,让我陪你辛苦!-2016携手前行>>

Reply all
Reply to author
Forward
0 new messages