英文:
I want to display 'yyy' in the index.html, but when running the server, the page displays normally but without the 'yyy'
问题
I want to display 'yyy'
in the index.html
, but when I run the server, the page is displayed normally, but 'yyy'
is not visible.
view.py
def index(request):
a1 = ''yyy''
return render(request, "index.html", {'a1': a1})
index.html
I want to display 'yyy'
in the index.html
, but when I run the server, the page is displayed normally, but 'yyy'
is not visible.
When I run:
python manage.py runserver
I see no errors.
英文:
i want to display 'yyy'
in the index.html
, but when I run the server , the page is displayed normally but 'yyy'
is not visible.
view.py
def index(request):
a1='yyy'
return render(request, "index.html", a1)
index.html
I want to display 'yyy'
in the index.html
. but when I run the server, the page displayed normally but 'yyy'
is not visible.
When I run:
python manage.py runserver
I see no errors.
答案1
得分: 1
尝试这个
你需要从视图将字典传递到模板。
https://docs.djangoproject.com/en/4.2/ref/templates/api/#django.template.Context
在视图中
def index(request):
context = {'a1': 'yyy'}
return render(request, "index.html", context)
在模板中
<h1>{{a1}}</h1>
英文:
try this
you need pass dict into template from view.
https://docs.djangoproject.com/en/4.2/ref/templates/api/#django.template.Context
def index(request):
context = {'a1': 'yyy'}
return render(request, "index.html", context)
in template
<h1>{{a1}}</h1>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论