在Python函数中,字典未返回键的完整值。

huangapple go评论101阅读模式
英文:

On python function the dictionary is not return the full value of the key?

问题

以下是您提供的代码的翻译部分:

App view code:

  1. def home(request):
  2. text1 = "示例名称"
  3. temp_dict = {'txt1': text1, 'txt2': '您的姓名'}
  4. return render(request, 'Second2_app/index.html', context=temp_dict)

index html code:

  1. <div>
  2. <label for="name">用户名</label>
  3. <input
  4. id="name"
  5. type="text"
  6. placeholder={{txt1}}
  7. name="name"
  8. required
  9. />
  10. </div>

项目文件中我定义的URL:

  1. urlpatterns = [
  2. path('admin/', admin.site.urls),
  3. path('', include('Second_app.urls')),
  4. path('Customers/', include('Second_app.urls')),
  5. ]

这些是您代码中的部分内容的中文翻译。如果您有任何其他需要,请随时提问。

英文:

App view code:

  1. def home(request):
  2. # return HttpResponse(&quot;&lt;h1&gt; This is Home Page &lt;/h1&gt;&quot;)
  3. text1 = &quot;Example Name&quot;
  4. temp_dict = {&#39;txt1&#39;: text1, &#39;txt2&#39;: &#39;Your Name&#39;}
  5. return render(request, &#39;Second2_app/index.html&#39;, context=temp_dict)

index html code:

  1. &lt;div&gt;
  2. &lt;label for=&quot;name&quot;&gt;User name&lt;/label&gt;
  3. &lt;input
  4. id=&quot;name&quot;
  5. type=&quot;text&quot;
  6. placeholder={{txt1}}
  7. name=&quot;name&quot;
  8. required
  9. /&gt;
  10. &lt;/div&gt;

url I define on project file

  1. urlpatterns = [
  2. path(&#39;admin/&#39;, admin.site.urls),
  3. path(&#39;&#39;, include(&#39;Second_app.urls&#39;)),
  4. path(&#39;Customers/&#39;, include(&#39;Second_app.urls&#39;)),
  5. ]

I am expecting why my desire output is not shown in the html file.......

答案1

得分: 1

我的问题解决了,这是我的愚蠢错误。

  1. &lt;div&gt;
  2. &lt;label for=&quot;name&quot;&gt;用户名&lt;/label&gt;
  3. &lt;input id=&quot;name&quot; type=&quot;text&quot; placeholder=&quot;{{txt1}}&quot; name=&quot;name&quot; required /&gt;
  4. &lt;/div&gt;
英文:

Got my solution it was a silly mistake from me.

  1. &lt;div&gt;
  2. &lt;label for=&quot;name&quot;&gt;User name&lt;/label&gt;
  3. &lt;input id=&quot;name&quot; type=&quot;text&quot; placeholder=&quot;{{txt1}}&quot; name=&quot;name&quot; required /&gt;
  4. &lt;/div&gt;

huangapple
  • 本文由 发表于 2023年5月18日 13:41:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76278035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定