{"id":268,"date":"2021-01-13T13:08:56","date_gmt":"2021-01-13T07:08:56","guid":{"rendered":"http:\/\/www.jichangqing.net\/wordpress\/?p=268"},"modified":"2021-01-13T13:46:54","modified_gmt":"2021-01-13T07:46:54","slug":"django2-0-%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e6%9d%bf%e6%a0%87%e7%ad%be-assignment_tag-%e5%ba%94%e8%af%a5-%e6%94%b9%e4%b8%ba-simple_tag","status":"publish","type":"post","link":"http:\/\/www.jichangqing.net\/wordpress\/?p=268","title":{"rendered":"Django2.0 \u81ea\u5b9a\u4e49\u6a21\u677f\u6807\u7b7e assignment_tag \u5e94\u8be5 \u6539\u4e3a simple_tag"},"content":{"rendered":"<p>django by example \u7b2c\u4e09\u7ae0\u62a5\u9519\uff1a<\/p>\n<p>@register.assignment_tag<br \/>\nAttributeError: &#8216;Library&#8217; object has no attribute &#8216;assignment_tag&#8217;<\/p>\n<p>&nbsp;<\/p>\n<blockquote>\n<pre class=\"has\" style=\"color: #000000;\"><code class=\"hljs kotlin\" style=\"color: #383a42;\">AttributeError: <span class=\"hljs-string\" style=\"color: #50a14f;\">'Library'<\/span> <span class=\"hljs-keyword\" style=\"color: #a626a4;\">object<\/span> has no attribute <span class=\"hljs-string\" style=\"color: #50a14f;\">'assignment_tag'<\/span><\/code><\/pre>\n<\/blockquote>\n<p style=\"color: #4d4d4d;\">You may be seeing this error after upgrading to Django 2.0. This is because\u00a0<a style=\"color: #6795b5;\" href=\"https:\/\/docs.djangoproject.com\/en\/stable\/releases\/1.9\/#assignment-tag\"><code>assignment_tag<\/code>\u00a0was deprecated in Django 1.9<\/a>, and removed in Django 2.0:<\/p>\n<blockquote>\n<p style=\"color: #4f4f4f;\">Django 1.4 added the\u00a0<code>assignment_tag<\/code>\u00a0helper to ease the creation of template tags that store results in a template variable. The\u00a0<code>simple_tag()<\/code>\u00a0helper has gained this same ability, making the\u00a0<code>assignment_tag<\/code>\u00a0obsolete. Tags that use\u00a0<code>assignment_tag<\/code>\u00a0should be updated to use\u00a0<code>simple_tag<\/code>.<\/p>\n<p style=\"color: #4f4f4f;\">from: https:\/\/blog.csdn.net\/maizhaoxi\/article\/details\/82719072<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>django by example \u7b2c\u4e09\u7ae0\u62a5\u9519\uff1a @register.assignment_tag AttributeError: &#8216;Library&#8217; object has no attribute &#8216;a &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-django"],"_links":{"self":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":1,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":269,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/269"}],"wp:attachment":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}