to access the filter query result passed to templates in django

shubhanjalee

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>]

jbiz

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Filter SQL query based on scalar function result

分類Dev

Filter nested query if no results in Django

分類Dev

How to filter a query on Django ORM

分類Dev

How to get filter key and result tuple in Django

分類Dev

How to access a column in laravel query result

分類Dev

JQL Query - Use a filter result in another JQL query

分類Dev

Query for students passed and not passed

分類Dev

Django - How to query a list inside of a filter method

分類Dev

Django query filter many to many to many etc

分類Dev

MS Access - Using Form Inputs to Filter on Multiple Criteria in a Query

分類Dev

Unable to access UserProfile model fields in templates in Django. Tried {{ user.userprofile }}

分類Dev

Django: Fastest way to random query one record using filter

分類Dev

How to modularize templates in django?

分類Dev

Filter group by result in DataFrame

分類Dev

MySQL filter by GROUP BY result

分類Dev

Inner Join query result to datagridview as products stock C# MS Access

分類Dev

django use of templates views and ajax

分類Dev

Django nested dictionary to display in templates

分類Dev

Use less files in django templates

分類Dev

Closure Templates: setting global variable from passed paramater in soy file

分類Dev

Why is typeof's result different than the evaluated result of the expression passed in?

分類Dev

Django - Edit templates from django admin

分類Dev

Limiting Query result in MongoDB

分類Dev

Force Result on Query IF true

分類Dev

Reuse the result of a query with PDO

分類Dev

Sending a query result in Json

分類Dev

running a query and then running a query for each result of that query

分類Dev

How to $slice a $filter result in MongoDB?

分類Dev

Scala filter collection by future result

Related 関連記事

  1. 1

    Filter SQL query based on scalar function result

  2. 2

    Filter nested query if no results in Django

  3. 3

    How to filter a query on Django ORM

  4. 4

    How to get filter key and result tuple in Django

  5. 5

    How to access a column in laravel query result

  6. 6

    JQL Query - Use a filter result in another JQL query

  7. 7

    Query for students passed and not passed

  8. 8

    Django - How to query a list inside of a filter method

  9. 9

    Django query filter many to many to many etc

  10. 10

    MS Access - Using Form Inputs to Filter on Multiple Criteria in a Query

  11. 11

    Unable to access UserProfile model fields in templates in Django. Tried {{ user.userprofile }}

  12. 12

    Django: Fastest way to random query one record using filter

  13. 13

    How to modularize templates in django?

  14. 14

    Filter group by result in DataFrame

  15. 15

    MySQL filter by GROUP BY result

  16. 16

    Inner Join query result to datagridview as products stock C# MS Access

  17. 17

    django use of templates views and ajax

  18. 18

    Django nested dictionary to display in templates

  19. 19

    Use less files in django templates

  20. 20

    Closure Templates: setting global variable from passed paramater in soy file

  21. 21

    Why is typeof's result different than the evaluated result of the expression passed in?

  22. 22

    Django - Edit templates from django admin

  23. 23

    Limiting Query result in MongoDB

  24. 24

    Force Result on Query IF true

  25. 25

    Reuse the result of a query with PDO

  26. 26

    Sending a query result in Json

  27. 27

    running a query and then running a query for each result of that query

  28. 28

    How to $slice a $filter result in MongoDB?

  29. 29

    Scala filter collection by future result

ホットタグ

アーカイブ