to access the filter query result passed to templates in django

1.2k views Asked by At

I want to pass the filter query result to the templates in the django. Details of each field of a row returned will be presented in the form of a readable form and like that for every row. I am using django 1.8

this is my urls.py

url(r'^pendingRegistrations/$',views.pendingApproval, name ='pendingApproval')

this is my views.py

from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template.context_processors import csrf
from django.views.decorators.csrf import csrf_protect
from django.core.mail import send_mail
from django.core import mail
from fcui.models import *
from django.db.models import Q
import urllib
from django.template import Context

@csrf_protect
def pendingApproval(request):


        if request.method == 'POST' :

                return HttpResponse("Post done")

        elif request.method == 'GET' :

                data = request.GET.get('id')
                decode = urllib.unquote_plus(data)

                from encryptData import encryption, decryption
                groupId = decryption(decode)
                print "group id : " + groupId
        #else :

        #       userId = request.user_id
        #       query = account_manager_users.objects.get(user_id = userId)
        #       groupId = query.group_id

        print "group id : " + groupId
        pending_users_list = pending_user_registrations.objects.filter(group_id = groupId)
        print pending_users_list

        c = Context({'pending_users_list',pending_users_list})
        c.update(csrf(request))
        return render_to_response('fcui/pendingRegistrations.html',c)

this is my .html (stored within app folder in templates folder)

{% block content %}

<h1 class="page-header">Pending User Registration Details</h1>


  {% if pending_users_list %}
        "cmn"
        {% for user_details in pending_users_list %}
                <form method="POST" action = "/appname/pendingRegistrations/">
                <table>
                <tr>
                <td>First Name : </td><td><input type = "text" name = "firstName" value = "{{user_details.first_name}}" readonly></input></t$
                </tr>
                <tr>
                <td>Last Name : </td><td><input type = "text" name = "lastName" value = "{{user_details.last_name}}" readonly></input></td>
                </tr>
                <tr>
                <td>User Name : </td><td><input type = "text" name = "userName" value = "{{user_details.user_name}}" readonly></input></td>
                </tr>
                <tr>
                <td>Email Address : </td><td><input type = "text" name = "emailAddress" value = "{{user_details.email_address}}" readonly></$
                </tr>
                <tr>
                <td>Joining Reason : </td><td><input type = "text" name = "reason" value = "{{user_details.joining_reason}}" readonly></inpu$
                </tr>
                </table>
                <br><br>
                <input type ="submit" name = "Submit" value= "Accept" ></input>
                <input type ="button" value= "Reject"></input><br>
                <input type = "hidden" name = "groupId" value = "{{user_details.group_id}}" readonly></input>
                {% csrf_token %}
                </form>

                <br><br><br>

        {% endfor %}
 {% else %}
        "not cmn"
 {% endif %}

but the screen shows "not cmn" even when the pending_users_list is not empty. Why is this happening ? Please help. I am new to django.

Edit :

this is what I see on console :

[<pending_user_registraions: PRIYA GOEL Priya29 [email protected] invited>]

1

There are 1 answers

0
jbiz On BEST ANSWER

For starters, it looks like you have an error on this line:

c = Context({'pending_users_list',pending_users_list})

where it should be:

c = Context({'pending_users_list': pending_users_list})

Note the comma is changed to a colon.