1

I have this views function to fetch userid and accountnumber from AWS Dynamodb :

 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.

 <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 ! Can someone resolve this issue ?

6
  • This code would not work at all, because render is expecting three arguments as Exprator says and would therefore interpret {'rows': rows} as the template name and throw a TemplateDoesNotExist error. Therefore, it seems that your view is not actually getting called. You probably need to show the urls.py and explain what URL you are going to. Commented Feb 14, 2018 at 11:08
  • I added request as an argument but still nothing is displayed on the template page. Commented Feb 14, 2018 at 11:10
  • I am not getting any error though Commented Feb 14, 2018 at 11:11
  • Yes, because as I said your view is not getting called. As I also said, you should post your urls.py and explain which URL you are actually visiting. Commented Feb 14, 2018 at 11:11
  • Okay.. But it's kind of a mess .. the urls.py Commented Feb 14, 2018 at 11:16

1 Answer 1

2
return render(request,'useradd.html',{'rows': rows})

you need to pass request as first parameter,

Sign up to request clarification or add additional context in comments.

4 Comments

I tried that.. doesn't work. Nothing shows up on the template page except the table headings
url(r'^adm/dsctbl2/', admviews.dsctbl2, name='dsctbl2'),
adm is the app name
you should add the full urls.py in the question,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.