{"id":6270,"date":"2022-04-06T13:52:16","date_gmt":"2022-04-06T05:52:16","guid":{"rendered":"https:\/\/egonlin.com\/?p=6270"},"modified":"2022-04-16T19:58:21","modified_gmt":"2022-04-16T11:58:21","slug":"%e7%ac%ac%e5%85%ad%e8%8a%82%ef%bc%9a%e4%b8%aa%e4%ba%ba%e7%ab%99%e5%8a%9f%e8%83%bd%e7%82%b9%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=6270","title":{"rendered":"\u7b2c\u516d\u8282\uff1a\u4e2a\u4eba\u7ad9\u529f\u80fd\u70b9\u8bbe\u8ba1"},"content":{"rendered":"<h1>\u4e2a\u4eba\u7ad9\u529f\u80fd\u70b9\u8bbe\u8ba1<\/h1>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u4e2a\u4eba\u7ad9\u70b9\u529f\u80fd\u8bbe\u8ba11.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u4e2a\u4eba\u7ad9\u70b9\u529f\u80fd\u8bbe\u8ba11.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>\u672c\u529f\u80fd\u9700\u6c42\uff1a<\/p>\n<p>-\u5de6\u4fa7\u4f7f\u7528inclusion_tag\u5bf9\u6807\u7b7e\u548c\u5206\u7c7b\u8fdb\u884c\u8fc7\u6ee4<\/p>\n<p>-\u5c55\u793a\u4e2a\u4eba\u7ad9\u70b9\u4e2d\u7684\u6587\u7ae0<\/p>\n<p>\u62d3\u5c55\u9700\u6c42:<\/p>\n<p>-\u5bf9\u6807\u7b7e\u548c\u5206\u7c7b\u8fdb\u884c\u7684\u589e\u5220\u6539\u64cd\u4f5c<\/p>\n<p>-\u521b\u5efa\u4e2a\u4eba\u7ad9\u70b9<\/p>\n<h2>\u4e00\u3001\u6dfb\u52a0\u8def\u7531<\/h2>\n<blockquote>\n<p>\u4e2a\u4eba\u7ad9\u70b9\u8def\u7531urls.py (\u6b64\u8def\u7531\u4e00\u5b9a\u8981\u653e\u5728\u6700\u540e)<\/p>\n<\/blockquote>\n<pre><code class=\"language-python\">    re_path(&#039;^(?P&lt;name&gt;\\w+)$&#039;, views.site, name=&#039;sites&#039;)<\/code><\/pre>\n<blockquote>\n<p>\u6b64\u5916\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6700\u5de6\u4fa7\u76843\u9879\u8fc7\u6ee4\u680f\u7684\u8def\u7531\u6574\u5408\u5230\u4e00\u8d77(\u4f7f\u7528\u6709\u540d\u5206\u7ec4\u7684\u5f62\u5f0f)<\/p>\n<\/blockquote>\n<p>\u8def\u7531\u6574\u5408 urls.py<\/p>\n<pre><code class=\"language-python\">    re_path(&#039;^(?P&lt;name&gt;\\w+)\/(?P&lt;query&gt;category|tag|archive)\/(?P&lt;condition&gt;.*).html$&#039;, views.site)<\/code><\/pre>\n<h2>\u4e8c\u3001\u6dfb\u52a0\u89c6\u56fe\u51fd\u6570<\/h2>\n<p>\u5728\u540e\u7aefviews.py\u4e2d\u6dfb\u52a0\u4e2a\u4eba\u4e3b\u9875\u8df3\u8f6c\u7684\u89c6\u56fe\u51fd\u6570<\/p>\n<pre><code class=\"language-python\">def site(request, name, **kwargs):\n    user = models.UserInfo.objects.filter(username=name).first()\n    if user:\n        try:\n            article_list = user.blog.article_set.all()\n            query = kwargs.get(&#039;query&#039;, None)\n            if query == &#039;category&#039;:\n                condition = kwargs.get(&#039;condition&#039;)\n                article_list = article_list.filter(category_id=condition)\n            elif query == &#039;tag&#039;:\n                condition = kwargs.get(&#039;condition&#039;)\n                article_list = article_list.filter(tag__id=condition)\n            elif query == &#039;archive&#039;:\n                condition = kwargs.get(&#039;condition&#039;)\n                year, month = condition.split(&#039;\/&#039;)\n                article_list = article_list.filter(create_time__year=year, create_time__month=month)\n            return render(request, &#039;site.html&#039;, locals())\n        except:\n            return render(request, &#039;other\/Error.html&#039;)\n    else:\n        return render(request, &#039;other\/Error.html&#039;)<\/code><\/pre>\n<h2>\u4e09\u3001\u4e2a\u4eba\u7ad9\u70b9\u529f\u80fd\u6d89\u53ca\u7684\u6a21\u578b\u5c42\u64cd\u4f5c<\/h2>\n<blockquote>\n<p>\u4e2a\u4eba\u7ad9\u70b9\u9875\u9762\u7684\u8def\u7531\u9700\u8981\u6d89\u53ca\u7528\u6237\u8868UserInfo\u4ee5\u53ca\u5bf9\u5e94\u7684\u535a\u5ba2\u8868Blog,\u4ece\u4e2d\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u4ee5\u53ca\u535a\u5ba2\u4fe1\u606f\u8fdb\u884c\u8df3\u8f6c<\/p>\n<p>\u4e2a\u4eba\u7ad9\u70b9\u5de6\u4fa7\u7684inclusion_tag\u8fc7\u6ee4\u680f\u662f\u5bf9\u6587\u7ae0\u8fdb\u884c\u6807\u7b7e\uff0c\u5206\u7c7b\u548c\u521b\u5efa\u65f6\u95f4\u7684\u8fc7\u6ee4\uff0c\u6240\u4ee5\u8981\u64cd\u4f5c\u6570\u636e\u5e93\u4e2d\u7684\u6587\u7ae0\u8868Article\uff08\u5176\u4e2d\u7684\u521b\u5efa\u65f6\u95f4\u5b57\u6bb5\uff09\u4ee5\u53ca\u6807\u7b7e\u8868\uff08Tag\uff09\u548c\u5206\u7c7b\u8868\uff08Category\uff09<\/p>\n<\/blockquote>\n<h2>\u56db\u3001\u4e2a\u4eba\u7ad9\u70b9\u529f\u80fd\u524d\u7aef\u6a21\u677f<\/h2>\n<h3>1\u3001\u4e2a\u4eba\u7ad9\u70b9\u9875\u9762\u8bbe\u8ba1(\u8be6\u60c5\u9875)<\/h3>\n<blockquote>\n<p>templates\u4e2d\u7684site.html(\u5728\u6b64\u9875\u9762\u4e2d\u7ee7\u627f\u4e86\u4e0a\u9762\u6240\u5199\u7684base.html)<\/p>\n<\/blockquote>\n<pre><code class=\"language-python\">{% extends &#039;template_base\/base.html&#039; %}\n\n{% block title %}\n    {{ user.blog.title }}\u7684\u4e2a\u4eba\u7ad9\u70b9\n{% endblock %}\n\n{% block content %}\n    &lt;div class=&quot;row&quot;&gt;\n        &lt;div class=&quot;col-md-2&quot;&gt;\n            {% load sideBar %}\n            {% left name %}\n        &lt;\/div&gt;\n        &lt;div class=&quot;col-md-8&quot;&gt;\n            &lt;nav aria-label=&quot;breadcrumb&quot;&gt;\n                &lt;ol class=&quot;breadcrumb&quot;&gt;\n                    \u5f53\u524d\u4f4d\u7f6e\uff1a\n                    &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;\/index\/&quot;&gt;\u9996\u9875&lt;\/a&gt;&lt;\/li&gt;\n                    &lt;li class=&quot;breadcrumb-item active&quot; aria-current=&quot;page&quot;&gt;{{ user.blog.title }}\u7684\u4e2a\u4eba\u7ad9\u70b9&lt;\/li&gt;\n                &lt;\/ol&gt;\n            &lt;\/nav&gt;\n            &lt;div class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;\u516c\u544a\uff1a&lt;\/strong&gt;{{ user.blog.subtitle }}&lt;\/div&gt;\n            {% for article in article_list %}\n                &lt;div class=&quot;m-4 p-1 shadow-sm site-title-head bg-white-95&quot;&gt;\n                    &lt;div class=&quot;media&quot;&gt;\n                        &lt;a href=&quot;\/{{ user.username }}\/article\/{{ article.id }}.html&quot;&gt;\n                            &lt;img src=&quot;\/media\/{{ article.head_img }}&quot; class=&quot;width-b100&quot; style=&quot;border-radius: 6px&quot;&gt;\n                        &lt;\/a&gt;\n                    &lt;\/div&gt;\n                    &lt;div class=&quot;mt-2 mx-3 mb-1 color-black-half&quot;&gt;\n                        &lt;a href=&quot;\/{{ user.username }}\/article\/{{ article.id }}.html&quot; class=&quot;font-24&quot;&gt;\n                            {{ article.title }}\n                        &lt;\/a&gt;\n                        &lt;hr class=&quot;mt-2 mb-2&quot;&gt;\n                        &lt;span class=&quot;mx-2&quot;&gt;\n                            &lt;i class=&quot;fa fa-user-o text-danger&quot;&gt;&lt;\/i&gt; {{ user.username }}\n                        &lt;\/span&gt;\n                        &lt;span class=&quot;mx-2&quot;&gt;\n                            &lt;i class=&quot;fa fa-clock-o text-info&quot;&gt;&lt;\/i&gt; {{ article.create_time|date:&#039;Y\u5e74m\u6708d\u65e5&#039; }}\n                        &lt;\/span&gt;\n                        &lt;span class=&quot;mx-2 width-80&quot;&gt;\n                            &lt;i class=&quot;fa fa-thumbs-o-up text-success&quot;&gt;&lt;\/i&gt; {{ article.up_num }}\u4eba\u70b9\u8d5e\n                        &lt;\/span&gt;\n                        &lt;span class=&quot;ml-2 width-80&quot;&gt;\n                            &lt;i class=&quot;fa fa-commenting-o text-warning&quot;&gt;&lt;\/i&gt; {{ article.comment_num }}\u6761\u8bc4\u8bba\n                        &lt;\/span&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            {% empty %}\n                &lt;div class=&quot;alert alert-warning alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;\n                    &lt;strong&gt;\u63d0\u793a\uff1a&lt;\/strong&gt;\u6682\u65e0\u6587\u7ae0\n                    &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;\n                        &lt;span aria-hidden=&quot;true&quot;&gt;\u00d7&lt;\/span&gt;\n                    &lt;\/button&gt;\n                &lt;\/div&gt;\n                &lt;div class=&quot;text-center&quot;&gt;\n                    &lt;img src=&quot;\/media\/emotion\/call.png&quot; width=&quot;600&quot; class=&quot;mt-3&quot;&gt;\n                    &lt;h1 class=&quot;ml-4&quot; style=&quot;font-size: 60px&quot;&gt;\u5feb\u53bb\u50ac\u535a\u4e3b\u5199\u6587\u7ae0\u5566\uff01&lt;\/h1&gt;\n                &lt;\/div&gt;\n            {% endfor %}\n        &lt;\/div&gt;\n        &lt;div class=&quot;col-md-2 text-center&quot;&gt;\n            &lt;img src=&quot;\/media\/{{ user.avatar }}&quot; width=&quot;100%&quot; style=&quot;border-radius: 10px&quot;&gt;\n            &lt;div class=&quot;text-left mt-2&quot; style=&quot;line-height: 30px&quot;&gt;\n                &lt;strong&gt;\u6635\u79f0\uff1a&lt;\/strong&gt;{{ user.blog.title }}&lt;br&gt;\n                &lt;strong&gt;\u6027\u522b\uff1a&lt;\/strong&gt;{% if user.gender == 1 %}\u7537\n            {% elif user.gender == 2 %}\u5973\n            {% else %}\u4fdd\u5bc6\n            {% endif %}\n                &lt;br&gt;\n                &lt;strong&gt;\u7535\u8bdd\uff1a&lt;\/strong&gt;{{ user.phone }}&lt;br&gt;\n                &lt;strong&gt;\u5730\u5740\uff1a&lt;\/strong&gt;{{ user.province }} {{ userinfo.city }}&lt;br&gt;\n                &lt;strong&gt;\u90ae\u7bb1\uff1a&lt;\/strong&gt;{{ user.email }}&lt;br&gt;\n                &lt;strong&gt;\u56ed\u9f84\uff1a&lt;\/strong&gt;{{ user.date_joined|timesince }}&lt;br&gt;\n                &lt;strong&gt;\u6ce8\u518c\u65e5\u671f\uff1a&lt;\/strong&gt;{{ user.date_joined|date:&#039;Y\u5e74m\u6708d\u65e5&#039; }}&lt;br&gt;\n                &lt;strong&gt;\u6700\u540e\u767b\u5f55\uff1a&lt;\/strong&gt;{{ user.last_login|date:&#039;m\u6708d\u65e5H:i&#039; }}&lt;br&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n\n    &lt;\/div&gt;\n{% endblock %}\n\n{% block js %}\n    &lt;script&gt;\n        $(&#039;body&#039;).attr(&#039;style&#039;, &#039;background:url(\/media\/{{ user.bg_img }}) !important;background-attachment: fixed !important;background-size: cover !important;&#039;)\n    &lt;\/script&gt;\n{% endblock %}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2a\u4eba\u7ad9\u529f\u80fd\u70b9\u8bbe\u8ba1 \u672c\u529f\u80fd\u9700\u6c42\uff1a -\u5de6\u4fa7\u4f7f\u7528inclusion_tag\u5bf9\u6807\u7b7e\u548c\u5206\u7c7b\u8fdb\u884c\u8fc7\u6ee4 -\u5c55\u793a\u4e2a\u4eba\u7ad9\u70b9\u4e2d\u7684\u6587 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":6812,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,406],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/6270"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6270"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/6270\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/6812"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}