访问传递给 django 模板的过滤器查询结果
to access the filter query result passed to templates in django
我想将过滤器查询结果传递给django 中的模板。返回的行的每个字段的详细信息将以可读形式呈现,就像每一行一样。我正在使用 Django 1.8
这是我的 urls.py
url(r'^pendingRegistrations/$',views.pendingApproval, name ='pendingApproval')
这是我的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)
这是我的。html(存储在模板文件夹中的应用程序文件夹中)
{% 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 %}
但屏幕显示“not cmn”,即使 pending_users_list 不为空。为什么会这样?请帮忙。我是 django 的新手。
编辑:
这是我在控制台上看到的:
[<pending_user_registraions: PRIYA GOEL Priya29 shubh@gmail.com invited>]
首先,您似乎在这一行有错误:
c = Context({'pending_users_list',pending_users_list})
它应该在哪里:
c = Context({'pending_users_list': pending_users_list})
请注意,逗号已更改为冒号。
我想将过滤器查询结果传递给django 中的模板。返回的行的每个字段的详细信息将以可读形式呈现,就像每一行一样。我正在使用 Django 1.8
这是我的 urls.py
url(r'^pendingRegistrations/$',views.pendingApproval, name ='pendingApproval')
这是我的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)
这是我的。html(存储在模板文件夹中的应用程序文件夹中)
{% 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 %}
但屏幕显示“not cmn”,即使 pending_users_list 不为空。为什么会这样?请帮忙。我是 django 的新手。
编辑:
这是我在控制台上看到的:
[<pending_user_registraions: PRIYA GOEL Priya29 shubh@gmail.com invited>]
首先,您似乎在这一行有错误:
c = Context({'pending_users_list',pending_users_list})
它应该在哪里:
c = Context({'pending_users_list': pending_users_list})
请注意,逗号已更改为冒号。