[英]Django : render not passing context variable to template
I have this views function to fetch userid and accountnumber from AWS Dynamodb : 我具有此视图功能,可从AWS Dynamodb获取用户ID和帐号:
def dsctbl2(request):
dynamodb=boto3.client('dynamodb', region_name='us-west-2')
response = dynamodb.scan(
TableName='User-Account')
filtered = response['Items']
length = len(filtered)
for k in range(length):
accnum = filtered[k]['AccountNum']['S']
uid = filtered[k]['UserId']['S']
f = dict(AccountNum=accnum,userID=uid)
rows = list(f.items())
return render('useradd.html',{'rows': rows})
I have tried almost everything but the rows value is just not getting passed to my template. 我已经尝试了几乎所有方法,但是行值只是没有传递到模板中。 I even tried passing a simple string value and even that is not getting passed.
我什至尝试传递一个简单的字符串值,即使没有传递。 This is my template table where I wish to display the userid and accountnum.
这是我的模板表,我希望在其中显示用户ID和accountnum。
<div class="mytable">
<table>
<thead>
<tr>
<th>Account #</th>
<th>User Id</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
<td>{{ row.AccountNum }}</td>
<td>{{ row.UserId }}</td>
</tr>
{% endfor %}
</table>
</div>
When I hit the template , nothing shows up. 当我点击模板时,什么都没有显示。 No values are getting displayed except the table headings.
除表标题外,未显示任何值。 Why is render not passing the context variable (list value)from my views to template ?
为什么渲染未将上下文变量(列表值)从我的视图传递到模板? I have been stuck with for about 6 hours !
我已经坚持了大约6个小时! Can someone resolve this issue ?
有人可以解决这个问题吗?
return render(request,'useradd.html',{'rows': rows})
您需要将请求作为第一个参数传递,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.