Python 我在一个字典中有两个字典,无法确定如何访问特定值
我试着看其他的例子,但没有一个对我有帮助, 我的问题是常量或视图中的某个地方,我似乎无法从CONSTANTS.PY的登录页中获取header的值。请帮助我找出我在VIEWS.PY中调用的是如何错误的 常数.PYPython 我在一个字典中有两个字典,无法确定如何访问特定值,python,html,django,Python,Html,Django,我试着看其他的例子,但没有一个对我有帮助, 我的问题是常量或视图中的某个地方,我似乎无法从CONSTANTS.PY的登录页中获取header的值。请帮助我找出我在VIEWS.PY中调用的是如何错误的 常数.PY videos = {'landing_page': { 'header': 'What\'s it like to take a class at ?', 'subheader': ' \"There are students who keep in touch for
videos = {'landing_page': {
'header': 'What\'s it like to take a class at ?',
'subheader': ' \"There are students who keep in touch for years after they\'ve taken a language class here.\" Learn more about the experience and what it means to learn a language with us in the video below. You\'re not just taking a class; you\'re getting an immersive experience and joining a growing community',
'url': 'https://www.youtube.com/'},
'private_lesson': {
'header': 'SEE WHAT A CLASS LOOKS LIKE AND MEET OUR TEACHERS',
'subheader': ' \"There are students who keep in touch for years after they\'ve taken a language class here.\" Learn more about the experience and what it means to learn a language with us in the video below. You\'re not just taking a class; you\'re getting an immersive experience and joining a growing community',
'url': 'https://www.youtube.com/'}}
VIEWS.PY
@render_to('video-section.html')
def video_section(request):
context = {}
context['headerLP'] = c.videos['landing_page']['header']
return context
HTML文件
{% load staticfiles %}
<section class="video-section">
<div class="padded-center-container">
<h2>{{ headerLP }}</h2>
<p>"There are students who keep in touch for years after they've
taken a language class here." Learn more about the he video
below. You're not just taking a class; you're getting an immersive
experience and joining a growing community.</p>
</div>
<div class="video-wrapper">
<iframe width="560" height="315"
src="https://www.youtube.com/" frameborder="0"
allowfullscreen></iframe>
</div>
</section>
{%load staticfiles%}
{{headerLP}}
“有些学生在毕业后会保持多年的联系
在这里上语言课。“了解更多有关he视频的信息
在下面你不仅仅是在上课;你得到了一个身临其境的感觉
体验并加入一个不断发展的社区
Python字典键不能是可变的,因此在get([{'subheader'}])
中使用列表没有意义。也许你想要c.videos['landing_page']['subheader']
或c.videos['landing_page']。如果你需要处理密钥不存在的情况,那么获取('subheader')
。你是否尝试从video_section()
打印c.videos
?要检查它是否像您给我们的示例。要清楚,是标题导致了问题,请忘记副标题。我尝试了c.videos['landing\u page']['header']
和c.videos['landing\u page'].get('subheader')
但我一直得到不好的模板变量你如何将视频字典从constants.py文件导入views.py??什么是c??如何从中访问c.视频。将常量导入为c