{"id":103990,"date":"2026-09-11T16:17:07","date_gmt":"2026-09-11T08:17:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/103990.html"},"modified":"2026-09-11T16:17:07","modified_gmt":"2026-09-11T08:17:07","slug":"django%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%ef%bc%88%e4%ba%94%ef%bc%89%ef%bc%9a%e6%a8%a1%e6%9d%bf%e7%b3%bb%e7%bb%9f%e8%af%a6%e8%a7%a3-%e5%8f%98%e9%87%8f%e3%80%81%e6%a0%87%e7%ad%be","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/103990.html","title":{"rendered":"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f"},"content":{"rendered":"<h5>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6a21\u677f\u7cfb\u7edf&#xff1f;<\/h5>\n<p>\u5728\u7b2c\u4e8c\u7bc7\u4e2d&#xff0c;\u6211\u4eec\u66fe\u7528\u00a0HttpResponse\u00a0\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<p>from django.http import HttpResponse<\/p>\n<p>def hello(request):<br \/>\n    return HttpResponse(&#034;Hello, Django!&#034;)<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355&#xff0c;\u4f46\u628a HTML \u5185\u5bb9\u786c\u7f16\u7801\u5728 Python \u4ee3\u7801\u91cc&#xff0c;\u5b58\u5728\u660e\u663e\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u636e\u4e0e\u89c6\u56fe\u6df7\u5408&#xff1a;\u8fdd\u53cd Django \u7684 MVT \u8bbe\u8ba1\u601d\u60f3\u3002<\/p>\n<\/li>\n<li>\n<p>\u65e0\u6cd5\u590d\u7528&#xff1a;\u9875\u9762\u5934\u90e8\u3001\u5c3e\u90e8\u7b49\u516c\u5171\u7ed3\u6784\u9700\u8981\u53cd\u590d\u7f16\u5199\u3002<\/p>\n<\/li>\n<li>\n<p>\u96be\u4ee5\u7ef4\u62a4&#xff1a;\u524d\u7aef\u6539\u52a8\u9700\u8981\u4fee\u6539 Python \u4ee3\u7801\u3002<\/p>\n<\/li>\n<\/ul>\n<p>Django \u7684\u6a21\u677f\u7cfb\u7edf&#xff08;Template System&#xff09;\u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u8bbe\u8ba1\u7684\u3002\u5b83\u5141\u8bb8\u4f60\u628a HTML \u7ed3\u6784\u4e0e Python \u6570\u636e\u5206\u79bb&#xff0c;\u901a\u8fc7\u7b80\u5355\u7684\u6807\u7b7e\u548c\u53d8\u91cf\u52a8\u6001\u751f\u6210\u9875\u9762\u3002<\/p>\n<p>\u6838\u5fc3\u80fd\u529b\u4e00\u89c8&#xff1a;<\/p>\n<table>\n<tr>\u529f\u80fd\u8bed\u6cd5\/\u793a\u4f8b\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u53d8\u91cf\u6e32\u67d3<\/td>\n<td>{{ variable }}<\/td>\n<td>\u52a8\u6001\u663e\u793a\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u903b\u8f91\u63a7\u5236<\/td>\n<td>{% if %}\u3001{% for %}<\/td>\n<td>\u6761\u4ef6\/\u5faa\u73af\u6e32\u67d3<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u677f\u7ee7\u627f<\/td>\n<td>{% extends %}\u3001{% block %}<\/td>\n<td>\u907f\u514d\u91cd\u590d HTML \u7ed3\u6784<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u6587\u4ef6<\/td>\n<td>{% static &#039;path&#039; %}<\/td>\n<td>\u52a0\u8f7d CSS\/JS\/\u56fe\u7247<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u5b9a\u4e49\u8fc7\u6ee4\u5668<\/td>\n<td>&#064;register.filter<\/td>\n<td>\u6269\u5c55\u6a21\u677f\u529f\u80fd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u4e8c\u3001\u7b2c\u4e00\u4e2a\u6a21\u677f&#xff1a;\u4ece HttpResponse \u5230 render<\/h5>\n<h6>1. \u521b\u5efa\u6a21\u677f\u76ee\u5f55\u4e0e\u6587\u4ef6<\/h6>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u00a0templates\u00a0\u76ee\u5f55&#xff0c;\u5e76\u65b0\u5efa\u00a0runoob.html&#xff1a;<\/p>\n<p>HelloWorld\/<br \/>\n\u251c\u2500\u2500 HelloWorld\/<br \/>\n\u2502   \u251c\u2500\u2500 settings.py<br \/>\n\u2502   \u251c\u2500\u2500 urls.py<br \/>\n\u2502   \u251c\u2500\u2500 views.py<br \/>\n\u2502   \u2514\u2500\u2500 wsgi.py<br \/>\n\u251c\u2500\u2500 manage.py<br \/>\n\u2514\u2500\u2500 templates\/<br \/>\n    \u2514\u2500\u2500 runoob.html<\/p>\n<p>runoob.html\u00a0\u5185\u5bb9&#xff1a;<\/p>\n<p>&lt;h1&gt;{{ hello }}&lt;\/h1&gt;<\/p>\n<p>\u5176\u4e2d\u00a0{{ hello }}\u00a0\u5c31\u662f\u6a21\u677f\u53d8\u91cf&#xff0c;\u4f7f\u7528\u53cc\u5927\u62ec\u53f7\u8bed\u6cd5\u3002<\/p>\n<h6>2. \u914d\u7f6e\u6a21\u677f\u8def\u5f84<\/h6>\n<p>\u6253\u5f00\u00a0settings.py&#xff0c;\u627e\u5230\u00a0TEMPLATES\u00a0\u914d\u7f6e&#xff0c;\u4fee\u6539\u00a0DIRS&#xff1a;<\/p>\n<p>TEMPLATES &#061; [<br \/>\n    {<br \/>\n        &#039;BACKEND&#039;: &#039;django.template.backends.django.DjangoTemplates&#039;,<br \/>\n        &#039;DIRS&#039;: [BASE_DIR \/ &#034;templates&#034;],   # \u4fee\u6539\u6b64\u5904<br \/>\n        &#039;APP_DIRS&#039;: True,<br \/>\n        &#039;OPTIONS&#039;: {<br \/>\n            &#039;context_processors&#039;: [<br \/>\n                &#039;django.template.context_processors.debug&#039;,<br \/>\n                &#039;django.template.context_processors.request&#039;,<br \/>\n                &#039;django.contrib.auth.context_processors.auth&#039;,<br \/>\n                &#039;django.contrib.messages.context_processors.messages&#039;,<br \/>\n            ],<br \/>\n        },<br \/>\n    },<br \/>\n]<\/p>\n<h6>3. \u7f16\u5199\u89c6\u56fe\u51fd\u6570<\/h6>\n<p>\u4fee\u6539\u00a0views.py&#xff0c;\u4f7f\u7528\u00a0render\u00a0\u66ff\u4ee3\u00a0HttpResponse&#xff1a;<\/p>\n<p>from django.shortcuts import render<\/p>\n<p>def runoob(request):<br \/>\n    context &#061; {}<br \/>\n    context[&#039;hello&#039;] &#061; &#039;Hello World!&#039;<br \/>\n    return render(request, &#039;runoob.html&#039;, context)<\/p>\n<p>render\u00a0\u7684\u4e09\u4e2a\u53c2\u6570&#xff1a;<\/p>\n<ul>\n<li>\n<p>request&#xff1a;HTTP \u8bf7\u6c42\u5bf9\u8c61&#xff08;\u5fc5\u987b&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>&#039;runoob.html&#039;&#xff1a;\u6a21\u677f\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<\/li>\n<li>\n<p>context&#xff1a;\u4f20\u9012\u7ed9\u6a21\u677f\u7684\u4e0a\u4e0b\u6587\u5b57\u5178\u3002\u5b57\u5178\u7684\u952e\u5bf9\u5e94\u6a21\u677f\u4e2d\u7684\u53d8\u91cf\u540d\u3002<\/p>\n<\/li>\n<\/ul>\n<h6>4. \u914d\u7f6e URL<\/h6>\n<p>from django.contrib import admin<br \/>\nfrom django.urls import path<br \/>\nfrom . import views<\/p>\n<p>urlpatterns &#061; [<br \/>\n    path(&#039;admin\/&#039;, admin.site.urls),<br \/>\n    path(&#039;runoob\/&#039;, views.runoob),<br \/>\n]<\/p>\n<p>\u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u8bbf\u95ee\u00a0http:\/\/127.0.0.1:8000\/runoob&#xff0c;\u5373\u53ef\u770b\u5230\u00a0Hello World!\u00a0\u88ab\u6e32\u67d3\u5230\u9875\u9762\u4e0a\u3002<\/p>\n<h5>\u4e09\u3001\u6a21\u677f\u53d8\u91cf<\/h5>\n<h6>1. \u57fa\u672c\u7528\u6cd5<\/h6>\n<p>\u89c6\u56fe\u4f20\u503c&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    views_name &#061; &#034;\u6559\u7a0b&#034;<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;name&#034;: views_name})<\/p>\n<p>\u6a21\u677f\u63a5\u6536&#xff1a;<\/p>\n<p>&lt;p&gt;{{ name }}&lt;\/p&gt;<\/p>\n<h6>2. \u5217\u8868\u7d22\u5f15<\/h6>\n<p>Django \u6a21\u677f\u4e2d\u4f7f\u7528\u00a0.\u00a0\u8bed\u6cd5\u8bbf\u95ee\u5217\u8868\u5143\u7d20&#xff08;\u6ce8\u610f\u4e0d\u662f\u00a0[]&#xff09;&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    views_list &#061; [&#034;\u6559\u7a0b1&#034;, &#034;\u6559\u7a0b2&#034;, &#034;\u6559\u7a0b3&#034;]<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;views_list&#034;: views_list})<\/p>\n<p>&lt;p&gt;{{ views_list }}&lt;\/p&gt;      {# \u53d6\u51fa\u6574\u4e2a\u5217\u8868 #}<br \/>\n&lt;p&gt;{{ views_list.0 }}&lt;\/p&gt;    {# \u53d6\u51fa\u7b2c\u4e00\u4e2a\u5143\u7d20 #}<\/p>\n<h6>3. \u5b57\u5178\u53d6\u503c<\/h6>\n<p>def runoob(request):<br \/>\n    views_dict &#061; {&#034;name&#034;: &#034;\u6559\u7a0b&#034;}<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;views_dict&#034;: views_dict})<\/p>\n<p>&lt;p&gt;{{ views_dict }}&lt;\/p&gt;<br \/>\n&lt;p&gt;{{ views_dict.name }}&lt;\/p&gt;<\/p>\n<p>\u8981\u70b9&#xff1a;\u00a0Django \u6a21\u677f\u4e2d\u7684\u00a0.\u00a0\u662f\u201c\u4e07\u80fd\u53d6\u503c\u7b26\u201d&#xff0c;\u4f1a\u4f9d\u6b21\u5c1d\u8bd5\u5b57\u5178\u952e\u3001\u5c5e\u6027\u3001\u5217\u8868\u7d22\u5f15&#xff0c;\u65e0\u9700\u533a\u5206\u00a0[]\u00a0\u548c\u00a0.\u3002<\/p>\n<h5>\u56db\u3001\u8fc7\u6ee4\u5668<\/h5>\n<p>\u8fc7\u6ee4\u5668\u7528\u4e8e\u5728\u53d8\u91cf\u8f93\u51fa\u524d\u5bf9\u5176\u8fdb\u884c\u4fee\u6539&#xff0c;\u8bed\u6cd5\u4e3a&#xff1a;<\/p>\n<p>{{ \u53d8\u91cf\u540d | \u8fc7\u6ee4\u5668:\u53ef\u9009\u53c2\u6570 }}<\/p>\n<h6>1. \u94fe\u5f0f\u8c03\u7528<\/h6>\n<p>\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5957\u63a5&#xff0c;\u524d\u4e00\u4e2a\u7684\u8f93\u51fa\u4f5c\u4e3a\u540e\u4e00\u4e2a\u7684\u8f93\u5165&#xff1a;<\/p>\n<p>{{ my_list|first|upper }}<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u53d6\u5217\u8868\u7b2c\u4e00\u4e2a\u5143\u7d20\u5e76\u8f6c\u4e3a\u5927\u5199\u3002<\/p>\n<h6>2. \u5e26\u53c2\u6570\u7684\u8fc7\u6ee4\u5668<\/h6>\n<p>\u53c2\u6570\u8ddf\u968f\u5192\u53f7&#xff0c;\u7528\u53cc\u5f15\u53f7\u5305\u88f9&#xff1a;<\/p>\n<p>{{ bio|truncatewords:&#034;30&#034; }}<\/p>\n<h6>3. \u5e38\u7528\u8fc7\u6ee4\u5668\u8be6\u89e3<\/h6>\n<table>\n<tr>\u8fc7\u6ee4\u5668\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>addslashes<\/td>\n<td>\u5728\u5f15\u53f7\u524d\u6dfb\u52a0\u53cd\u659c\u6760<\/td>\n<td>{{ name|addslashes }}<\/td>\n<\/tr>\n<tr>\n<td>date<\/td>\n<td>\u683c\u5f0f\u5316\u65e5\u671f\u65f6\u95f4<\/td>\n<td>{{ pub_date|date:&#034;F j, Y&#034; }}<\/td>\n<\/tr>\n<tr>\n<td>length<\/td>\n<td>\u8fd4\u56de\u957f\u5ea6<\/td>\n<td>{{ name|length }}<\/td>\n<\/tr>\n<tr>\n<td>default<\/td>\n<td>\u53d8\u91cf\u4e3a\u5047\u65f6\u63d0\u4f9b\u9ed8\u8ba4\u503c<\/td>\n<td>{{ name|default:&#034;\u83dc\u9e1f\u6559\u7a0b666&#034; }}<\/td>\n<\/tr>\n<tr>\n<td>filesizeformat<\/td>\n<td>\u6613\u8bfb\u7684\u6587\u4ef6\u5927\u5c0f<\/td>\n<td>{{ num|filesizeformat }}<\/td>\n<\/tr>\n<tr>\n<td>truncatechars<\/td>\n<td>\u622a\u65ad\u5b57\u7b26\u4e32&#xff0c;\u4ee5\u00a0&#8230;\u00a0\u7ed3\u5c3e<\/td>\n<td>{{ views_str|truncatechars:2 }}<\/td>\n<\/tr>\n<tr>\n<td>safe<\/td>\n<td>\u6807\u8bb0\u4e3a\u5b89\u5168&#xff0c;\u4e0d\u8f6c\u4e49<\/td>\n<td>{{ views_str|safe }}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>default \u8fc7\u6ee4\u5668\u793a\u4f8b&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    name &#061; 0<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;name&#034;: name})<\/p>\n<p>{{ name|default:&#034;\u6559\u7a0b666&#034; }}<\/p>\n<p>\u4ee5\u4e0b\u503c\u4f1a\u88ab\u89c6\u4e3a\u5047&#xff08;false&#xff09;&#xff0c;\u89e6\u53d1\u9ed8\u8ba4\u503c&#xff1a;0\u30010.0\u3001False\u30010j\u3001&#034;&#034;\u3001[]\u3001()\u3001set()\u3001{}\u3001None\u3002<\/p>\n<p>length \u8fc7\u6ee4\u5668\u793a\u4f8b&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    name &#061; &#034;\u83dc\u9e1f\u6559\u7a0b&#034;<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;name&#034;: name})<\/p>\n<p>{{ name|length }}<\/p>\n<p>\u5b57\u5178\u8fd4\u56de\u952e\u503c\u5bf9\u6570\u91cf&#xff0c;\u96c6\u5408\u8fd4\u56de\u53bb\u91cd\u540e\u7684\u957f\u5ea6\u3002<\/p>\n<p>filesizeformat \u8fc7\u6ee4\u5668\u793a\u4f8b&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    num &#061; 1024<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;num&#034;: num})<\/p>\n<p>{{ num|filesizeformat }}<\/p>\n<p>\u8f93\u51fa\u7c7b\u4f3c\u00a01.0 KB\u3002<\/p>\n<p>date \u8fc7\u6ee4\u5668\u793a\u4f8b&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    import datetime<br \/>\n    now &#061; datetime.datetime.now()<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;time&#034;: now})<\/p>\n<p>{{ time|date:&#034;Y-m-d&#034; }}<\/p>\n<p>\u8f93\u51fa\u5982\u00a02026-09-11\u3002<\/p>\n<p>truncatechars \u8fc7\u6ee4\u5668\u793a\u4f8b&#xff1a;<\/p>\n<p>{{ views_str|truncatechars:2 }}<\/p>\n<p>\u8f93\u51fa\u00a0\u83dc\u9e1f&#8230;\u3002<\/p>\n<p>safe \u8fc7\u6ee4\u5668&#xff08;\u91cd\u70b9&#xff09;&#xff1a;<\/p>\n<p>Django \u9ed8\u8ba4\u4f1a\u5bf9\u53d8\u91cf\u4e2d\u7684 HTML \u6807\u7b7e\u8fdb\u884c\u8f6c\u4e49&#xff0c;\u9632\u6b62 XSS \u653b\u51fb\u3002\u5982\u679c\u6570\u636e\u786e\u5b9e\u5b89\u5168&#xff0c;\u53ef\u4ee5\u7528\u00a0safe\u00a0\u544a\u8bc9 Django \u4e0d\u5fc5\u8f6c\u4e49&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    views_str &#061; &#034;&lt;a href&#061;&#039;https:\/\/www.runoob.com\/&#039;&gt;\u70b9\u51fb\u8df3\u8f6c&lt;\/a&gt;&#034;<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;views_str&#034;: views_str})<\/p>\n<p>{{ views_str|safe }}<\/p>\n<p>\u5b89\u5168\u63d0\u9192&#xff1a;\u00a0\u53ea\u6709\u5728\u4f60\u5b8c\u5168\u4fe1\u4efb\u6570\u636e\u6765\u6e90\u65f6\u624d\u4f7f\u7528\u00a0safe&#xff0c;\u5426\u5219\u4f1a\u5f15\u5165 XSS \u6f0f\u6d1e\u3002<\/p>\n<h5>\u4e94\u3001\u903b\u8f91\u6807\u7b7e&#xff1a;if \u4e0e for<\/h5>\n<h6>1. if \/ elif \/ else<\/h6>\n<p>{% if condition1 %}<br \/>\n   &#8230; display 1<br \/>\n{% elif condition2 %}<br \/>\n   &#8230; display 2<br \/>\n{% else %}<br \/>\n   &#8230; display 3<br \/>\n{% endif %}<\/p>\n<p>\u652f\u6301\u00a0and\u3001or\u3001not\u00a0\u7ec4\u5408\u5224\u65ad&#xff1a;<\/p>\n<p>{% if athlete_list and coach_list %}<br \/>\n     athletes \u548c coaches \u53d8\u91cf\u90fd\u662f\u53ef\u7528\u7684\u3002<br \/>\n{% endif %}<\/p>\n<p>\u5b9e\u4f8b&#xff1a;<\/p>\n<p>def runoob(request):<br \/>\n    views_num &#061; 88<br \/>\n    return render(request, &#034;runoob.html&#034;, {&#034;num&#034;: views_num})<\/p>\n<p>{% if num &gt; 90 and num &lt;&#061; 100 %}<br \/>\n\u4f18\u79c0<br \/>\n{% elif num &gt; 60 and num &lt;&#061; 90 %}<br \/>\n\u5408\u683c<br \/>\n{% else %}<br \/>\n\u4e00\u8fb9\u73a9\u53bb&#xff5e;<br \/>\n{% endif %}<\/p>\n<h6>2. for \u5faa\u73af<\/h6>\n<p>&lt;ul&gt;<br \/>\n{% for athlete in athlete_list %}<br \/>\n    &lt;li&gt;{{ athlete.name }}&lt;\/li&gt;<br \/>\n{% endfor %}<br \/>\n&lt;\/ul&gt;<\/p>\n<p>\u53cd\u5411\u8fed\u4ee3&#xff1a;<\/p>\n<p>{% for i in views_list reversed %}<br \/>\n{{ i }}<br \/>\n{% endfor %}<\/p>\n<p>\u904d\u5386\u5b57\u5178&#xff1a;<\/p>\n<p>{% for i,j in views_dict.items %}<br \/>\n{{ i }}&#8212;{{ j }}<br \/>\n{% endfor %}<\/p>\n<p>forloop \u53d8\u91cf&#xff1a;<\/p>\n<table>\n<tr>\u53d8\u91cf\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>forloop.counter<\/td>\n<td>\u4ece 1 \u5f00\u59cb\u8ba1\u6570<\/td>\n<\/tr>\n<tr>\n<td>forloop.counter0<\/td>\n<td>\u4ece 0 \u5f00\u59cb\u8ba1\u6570<\/td>\n<\/tr>\n<tr>\n<td>forloop.revcounter<\/td>\n<td>\u5012\u5e8f&#xff0c;\u7ed3\u5c3e\u4e3a 1<\/td>\n<\/tr>\n<tr>\n<td>forloop.revcounter0<\/td>\n<td>\u5012\u5e8f&#xff0c;\u7ed3\u5c3e\u4e3a 0<\/td>\n<\/tr>\n<tr>\n<td>forloop.first<\/td>\n<td>\u7b2c\u4e00\u6761\u6570\u636e\u8fd4\u56de True<\/td>\n<\/tr>\n<tr>\n<td>forloop.last<\/td>\n<td>\u6700\u540e\u4e00\u6761\u6570\u636e\u8fd4\u56de True<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>{% for i in listvar %}<br \/>\n    {{ forloop.counter }} &#8211; {{ forloop.first }} &#8211; {{ forloop.last }}<br \/>\n{% endfor %}<\/p>\n<p>empty \u4ece\u53e5&#xff1a;<\/p>\n<p>\u5f53\u5faa\u73af\u5bf9\u8c61\u4e3a\u7a7a\u65f6\u6267\u884c&#xff1a;<\/p>\n<p>{% for i in listvar %}<br \/>\n    {{ forloop.counter0 }}<br \/>\n{% empty %}<br \/>\n    \u7a7a\u7a7a\u5982\u4e5f&#xff5e;<br \/>\n{% endfor %}<\/p>\n<p>\u5d4c\u5957\u5faa\u73af&#xff1a;<\/p>\n<p>{% for athlete in athlete_list %}<br \/>\n    &lt;h1&gt;{{ athlete.name }}&lt;\/h1&gt;<br \/>\n    &lt;ul&gt;<br \/>\n    {% for sport in athlete.sports_played %}<br \/>\n        &lt;li&gt;{{ sport }}&lt;\/li&gt;<br \/>\n    {% endfor %}<br \/>\n    &lt;\/ul&gt;<br \/>\n{% endfor %}<\/p>\n<h5>\u516d\u3001\u6ce8\u91ca\u3001include \u4e0e csrf_token<\/h5>\n<p>\u6ce8\u91ca&#xff1a;<\/p>\n<p>{# \u8fd9\u662f\u4e00\u4e2a\u6ce8\u91ca #}<\/p>\n<p>include \u6807\u7b7e&#xff1a;<br \/>\n\u5c06\u5176\u4ed6\u6a21\u677f\u7247\u6bb5\u5d4c\u5165\u5f53\u524d\u6a21\u677f&#xff0c;\u5e38\u7528\u4e8e\u62bd\u53d6\u5bfc\u822a\u680f\u3001\u9875\u811a&#xff1a;<\/p>\n<p>{% include &#034;nav.html&#034; %}<\/p>\n<p>csrf_token&#xff08;\u8868\u5355\u5fc5\u7528&#xff09;&#xff1a;<br \/>\n\u5728 form \u8868\u5355\u4e2d\u5fc5\u987b\u52a0\u4e0a\u6b64\u6807\u7b7e&#xff0c;\u5426\u5219\u63d0\u4ea4\u65f6\u4f1a\u62a5 403 \u9519\u8bef&#xff1a;<\/p>\n<p>&lt;form method&#061;&#034;post&#034;&gt;<br \/>\n    {% csrf_token %}<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;username&#034;&gt;<br \/>\n    &lt;button type&#061;&#034;submit&#034;&gt;\u63d0\u4ea4&lt;\/button&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>\u5de5\u4f5c\u539f\u7406&#xff1a;\u00a0Django \u7684 CSRF \u4e2d\u95f4\u4ef6\u4f1a\u5411\u767b\u5f55\u9875\u9762\u6ce8\u5165\u4e00\u4e2a\u9690\u85cf\u7684\u968f\u673a token&#xff0c;\u8868\u5355\u63d0\u4ea4\u65f6\u643a\u5e26\u8be5 token&#xff0c;\u4e2d\u95f4\u4ef6\u6821\u9a8c\u901a\u8fc7\u624d\u5141\u8bb8\u63d0\u4ea4\u3002<\/p>\n<h5>\u4e03\u3001\u81ea\u5b9a\u4e49\u6807\u7b7e\u4e0e\u8fc7\u6ee4\u5668<\/h5>\n<p>\u5f53\u5185\u7f6e\u529f\u80fd\u4e0d\u591f\u7528\u65f6&#xff0c;\u53ef\u4ee5\u81ea\u5b9a\u4e49\u3002\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<p>1. \u5728\u5e94\u7528\u76ee\u5f55\u4e0b\u521b\u5efa\u00a0templatetags\u00a0\u76ee\u5f55&#xff08;\u76ee\u5f55\u540d\u56fa\u5b9a&#xff0c;\u4e0d\u80fd\u66f4\u6539&#xff09;&#xff1a;<\/p>\n<p>HelloWorld\/<br \/>\n\u251c\u2500\u2500 HelloWorld\/<br \/>\n\u251c\u2500\u2500 templatetags\/<br \/>\n\u2502   \u2514\u2500\u2500 my_tags.py<br \/>\n\u251c\u2500\u2500 manage.py<br \/>\n\u2514\u2500\u2500 templates\/<\/p>\n<p>2. \u521b\u5efa\u00a0my_tags.py&#xff1a;<\/p>\n<p>from django import template<\/p>\n<p>register &#061; template.Library()   # register \u540d\u79f0\u56fa\u5b9a&#xff0c;\u4e0d\u53ef\u6539\u53d8<\/p>\n<p>3. \u5728 settings.py \u4e2d\u914d\u7f6e libraries&#xff1a;<\/p>\n<p>TEMPLATES &#061; [<br \/>\n    {<br \/>\n        # &#8230;<br \/>\n        &#039;OPTIONS&#039;: {<br \/>\n            &#039;context_processors&#039;: [<br \/>\n                # &#8230;<br \/>\n            ],<br \/>\n            &#034;libraries&#034;: {<br \/>\n                &#039;my_tags&#039;: &#039;templatetags.my_tags&#039;<br \/>\n            }<br \/>\n        },<br \/>\n    },<br \/>\n]<\/p>\n<p>4. \u5b9a\u4e49\u8fc7\u6ee4\u5668&#xff08;&#064;register.filter&#xff09;&#xff1a;<\/p>\n<p>&#064;register.filter<br \/>\ndef my_filter(v1, v2):<br \/>\n    return v1 * v2<\/p>\n<p>5. \u5b9a\u4e49\u6807\u7b7e&#xff08;&#064;register.simple_tag&#xff09;&#xff1a;<\/p>\n<p>&#064;register.simple_tag<br \/>\ndef my_tag1(v1, v2, v3):<br \/>\n    return v1 * v2 * v3<\/p>\n<p>6. \u5728\u6a21\u677f\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528&#xff1a;<\/p>\n<p>{% load my_tags %}<\/p>\n<p>{{ 11|my_filter:22 }}<\/p>\n<p>{% my_tag1 11 22 33 %}<\/p>\n<p>7. \u8bed\u4e49\u5316\u6807\u7b7e&#xff1a;<br \/>\n\u4f7f\u7528\u00a0mark_safe\u00a0\u8ba9\u8fd4\u56de\u7684 HTML \u751f\u6548&#xff1a;<\/p>\n<p>from django.utils.safestring import mark_safe<\/p>\n<p>&#064;register.simple_tag<br \/>\ndef my_html(v1, v2):<br \/>\n    temp_html &#061; &#034;&lt;input type&#061;&#039;text&#039; id&#061;&#039;%s&#039; class&#061;&#039;%s&#039; \/&gt;&#034; % (v1, v2)<br \/>\n    return mark_safe(temp_html)<\/p>\n<p>{% my_html &#034;zzz&#034; &#034;xxx&#034; %}<\/p>\n<p>\u6548\u679c\u7b49\u540c\u4e8e\u524d\u7aef\u8fc7\u6ee4\u5668\u7684\u00a0safe\u3002<\/p>\n<h5>\u516b\u3001\u914d\u7f6e\u9759\u6001\u6587\u4ef6<\/h5>\n<p>\u9759\u6001\u6587\u4ef6\u6307 CSS\u3001JavaScript\u3001\u56fe\u7247\u3001\u63d2\u4ef6\u7b49\u3002\u914d\u7f6e\u6b65\u9aa4&#xff1a;<\/p>\n<p>1. \u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u00a0statics\u00a0\u76ee\u5f55&#xff1a;<\/p>\n<p>statics\/<br \/>\n\u251c\u2500\u2500 css\/<br \/>\n\u251c\u2500\u2500 js\/<br \/>\n\u251c\u2500\u2500 images\/<br \/>\n\u2514\u2500\u2500 plugins\/<\/p>\n<p>2. \u5728\u00a0settings.py\u00a0\u4e2d\u914d\u7f6e&#xff1a;<\/p>\n<p>STATIC_URL &#061; &#039;\/static\/&#039;   # URL \u522b\u540d<br \/>\nSTATICFILES_DIRS &#061; [<br \/>\n    os.path.join(BASE_DIR, &#034;statics&#034;),<br \/>\n]<\/p>\n<p>3. \u5728\u6a21\u677f\u4e2d\u52a0\u8f7d\u9759\u6001\u6587\u4ef6&#xff1a;<\/p>\n<p>{% load static %}<br \/>\n{{ name }}&lt;img src&#061;&#034;{% static &#039;images\/runoob-logo.png&#039; %}&#034; alt&#061;&#034;runoob-logo&#034;&gt;<\/p>\n<p>4. \u5f15\u5165\u5916\u90e8\u6846\u67b6&#xff08;\u5982 Bootstrap&#xff09;&#xff1a;<\/p>\n<p>\u628a Bootstrap \u653e\u5165\u00a0plugins\u00a0\u76ee\u5f55&#xff0c;\u7136\u540e\u5728 HTML head \u4e2d\u5f15\u5165\u3002\u6ce8\u610f\u8def\u5f84\u4f7f\u7528\u00a0static\u00a0\u522b\u540d\u800c\u975e\u76ee\u5f55\u540d\u00a0statics&#xff1a;<\/p>\n<p>&lt;link rel&#061;&#034;stylesheet&#034; href&#061;&#034;\/static\/plugins\/bootstrap-3.3.7\/dist\/css\/bootstrap.css&#034;&gt;<\/p>\n<h5>\u4e5d\u3001\u6a21\u677f\u7ee7\u627f<\/h5>\n<p>\u6a21\u677f\u7ee7\u627f\u662f Django \u6a21\u677f\u7cfb\u7edf\u6700\u5f3a\u5927\u7684\u7279\u6027&#xff0c;\u7528\u4e8e\u6d88\u9664\u9875\u9762\u4e2d\u7684\u91cd\u590d\u7ed3\u6784\u3002<\/p>\n<p>\u7236\u6a21\u677f\u00a0base.html&#xff1a;<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta charset&#061;&#034;utf-8&#034;&gt;<br \/>\n&lt;title&gt;\u83dc\u9e1f\u6559\u7a0b(runoob.com)&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;h1&gt;Hello World!&lt;\/h1&gt;<br \/>\n    &lt;p&gt;\u83dc\u9e1f\u6559\u7a0b Django \u6d4b\u8bd5\u3002&lt;\/p&gt;<br \/>\n    {% block mainbody %}<br \/>\n       &lt;p&gt;original&lt;\/p&gt;<br \/>\n    {% endblock %}<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>{% block mainbody %}\u00a0\u662f\u9884\u7559\u533a\u57df&#xff0c;\u5b50\u6a21\u677f\u53ef\u4ee5\u66ff\u6362\u5b83\u3002<\/p>\n<p>\u5b50\u6a21\u677f\u00a0runoob.html&#xff1a;<\/p>\n<p>{% extends &#034;base.html&#034; %}<\/p>\n<p>{% block mainbody %}<br \/>\n&lt;p&gt;\u7ee7\u627f\u4e86 base.html \u6587\u4ef6&lt;\/p&gt;<br \/>\n{% endblock %}<\/p>\n<p>\u89c4\u5219\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>{% extends %}\u00a0\u5fc5\u987b\u662f\u5b50\u6a21\u677f\u7684\u7b2c\u4e00\u884c\u6807\u7b7e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b50\u6a21\u677f\u53ea\u8d1f\u8d23\u586b\u5145 block&#xff0c;\u4e0d\u9700\u8981\u91cd\u590d\u7236\u6a21\u677f\u7684 HTML \u7ed3\u6784\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u5b50\u6a21\u677f\u4e0d\u8986\u76d6\u67d0\u4e2a block&#xff0c;\u5219\u4f7f\u7528\u7236\u6a21\u677f\u7684\u9ed8\u8ba4\u5185\u5bb9\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u540c block \u7684\u540d\u5b57\u4e0d\u80fd\u76f8\u540c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6a21\u677f\u7ee7\u627f\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<h5>\u5341\u3001\u5c0f\u7ed3<\/h5>\n<p>\u672c\u7bc7\u7cfb\u7edf\u8bb2\u89e3\u4e86 Django \u6a21\u677f\u7cfb\u7edf\u7684\u6838\u5fc3\u5185\u5bb9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u53d8\u91cf\u6e32\u67d3&#xff1a;{{ variable }}&#xff0c;\u652f\u6301\u5b57\u5178\u3001\u5217\u8868\u3001\u5bf9\u8c61\u5c5e\u6027\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fc7\u6ee4\u5668&#xff1a;{{ var|filter:arg }}&#xff0c;\u5e38\u7528\u6709\u00a0default\u3001length\u3001date\u3001safe\u00a0\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u903b\u8f91\u6807\u7b7e&#xff1a;{% if %}\u3001{% for %}&#xff0c;\u914d\u5408\u00a0forloop\u00a0\u548c\u00a0{% empty %}\u00a0\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u6a21\u677f\u7ee7\u627f&#xff1a;{% extends %}\u00a0&#043;\u00a0{% block %}&#xff0c;\u662f\u6d88\u9664\u91cd\u590d HTML \u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/li>\n<li>\n<p>\u9759\u6001\u6587\u4ef6&#xff1a;{% static %}\u00a0\u52a0\u8f7d CSS\/JS\/\u56fe\u7247&#xff0c;\u9700\u5148\u914d\u7f6e\u00a0STATICFILES_DIRS\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u6807\u7b7e\u4e0e\u8fc7\u6ee4\u5668&#xff1a;\u901a\u8fc7\u00a0templatetags\u00a0\u76ee\u5f55\u6269\u5c55\u6a21\u677f\u80fd\u529b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9\u540e&#xff0c;\u4f60\u5df2\u7ecf\u80fd\u591f\u6784\u5efa\u7ed3\u6784\u6e05\u6670\u3001\u6613\u4e8e\u7ef4\u62a4\u7684\u524d\u7aef\u9875\u9762\u3002\u4e0b\u4e00\u7bc7\u6211\u4eec\u5c06\u8fdb\u5165 Django \u7684\u6838\u5fc3\u2014\u2014Model \u6a21\u578b\u5c42&#xff0c;\u5b66\u4e60\u5982\u4f55\u7528 Python \u7c7b\u5b9a\u4e49\u6570\u636e\u5e93\u8868&#xff0c;\u5e76\u901a\u8fc7 ORM \u5b8c\u6210\u6570\u636e\u7684\u589e\u5220\u6539\u67e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6a21\u677f\u7cfb\u7edf&#xff1f;\u5728\u7b2c\u4e8c\u7bc7\u4e2d&#xff0c;\u6211\u4eec\u66fe\u7528\u00a0HttpResponse\u00a0\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff1a;from django.http import HttpResponsedef hello(request):return HttpResponse(\\&#8221;Hello, Django!\\&#8221;)\u8fd9\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355&#xff0c;\u4f46\u628a HTML \u5185\u5bb9\u786c\u7f16\u7801\u5728 Python \u4ee3\u7801\u91cc&#xff0c;\u5b58\u5728\u660e\u663e\u95ee\u9898&#xff1a;\u6570\u636e\u4e0e\u89c6\u56fe\u6df7\u5408&#xff1a;\u8fdd\u53cd Dj<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[890,2547,100],"topic":[],"class_list":["post-103990","post","type-post","status-publish","format-standard","hentry","category-server","tag-django","tag-sqlite","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/103990.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6a21\u677f\u7cfb\u7edf&#xff1f;\u5728\u7b2c\u4e8c\u7bc7\u4e2d&#xff0c;\u6211\u4eec\u66fe\u7528\u00a0HttpResponse\u00a0\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff1a;from django.http import HttpResponsedef hello(request):return HttpResponse(&quot;Hello, Django!&quot;)\u8fd9\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355&#xff0c;\u4f46\u628a HTML \u5185\u5bb9\u786c\u7f16\u7801\u5728 Python \u4ee3\u7801\u91cc&#xff0c;\u5b58\u5728\u660e\u663e\u95ee\u9898&#xff1a;\u6570\u636e\u4e0e\u89c6\u56fe\u6df7\u5408&#xff1a;\u8fdd\u53cd Dj\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/103990.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-11T08:17:07+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/103990.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/103990.html\",\"name\":\"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-11T08:17:07+00:00\",\"dateModified\":\"2026-09-11T08:17:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/103990.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/103990.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/103990.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/103990.html","og_locale":"zh_CN","og_type":"article","og_title":"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6a21\u677f\u7cfb\u7edf&#xff1f;\u5728\u7b2c\u4e8c\u7bc7\u4e2d&#xff0c;\u6211\u4eec\u66fe\u7528\u00a0HttpResponse\u00a0\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff1a;from django.http import HttpResponsedef hello(request):return HttpResponse(\"Hello, Django!\")\u8fd9\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355&#xff0c;\u4f46\u628a HTML \u5185\u5bb9\u786c\u7f16\u7801\u5728 Python \u4ee3\u7801\u91cc&#xff0c;\u5b58\u5728\u660e\u663e\u95ee\u9898&#xff1a;\u6570\u636e\u4e0e\u89c6\u56fe\u6df7\u5408&#xff1a;\u8fdd\u53cd Dj","og_url":"https:\/\/www.wsisp.com\/helps\/103990.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-11T08:17:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/103990.html","url":"https:\/\/www.wsisp.com\/helps\/103990.html","name":"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-11T08:17:07+00:00","dateModified":"2026-09-11T08:17:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/103990.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/103990.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/103990.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Django\u5165\u95e8\u6559\u7a0b\uff08\u4e94\uff09\uff1a\u6a21\u677f\u7cfb\u7edf\u8be6\u89e3\u2014\u2014\u53d8\u91cf\u3001\u6807\u7b7e\u3001\u8fc7\u6ee4\u5668\u4e0e\u6a21\u677f\u7ee7\u627f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/103990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=103990"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/103990\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=103990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=103990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=103990"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=103990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}