我只是想學習一個django項目。我已經使用django命令創建了項目和項目myapp。
在目錄/myproject的/ MYAPP $我views.py文件。另一個目錄/myproject/myapp /模板$我有hello.html文件。我想使用渲染函數將字典值從views.py文件發送到hello.html文件。但我得到一些錯誤稱爲如何將django應用程序中的字典值從視圖傳遞到模板
**Internal Server Error: /hello/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 42, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/joy/pythonWork/myproject/myapp/views.py", line 8, in hello
name : 'xyz',
NameError: global name 'name' is not defined**
我不知道,如何解決這個問題。有人請幫助我。 我的文件將在下面進行:
/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def hello(request):
personalDetails = {
name : 'xyz',
phoneno : '722924374'
}
return render(request, "hello.html", {personalDetails})
/hello.html
<html>
<body>
<h1>Hello</h1>{{personalDetails}}
</body>
</html>
在瀏覽器:NameError在/你好/全球名 'name' 沒有定義請求方法:\t GET .... – Roy
派息你解決'{{personalDetails}}''到{{} personalDeatils.name }'? – bismute