Thursday, December 21, 2017

Re: I want to display my restaurant list for which i used a function based view and it is working fine but when i import generic list view then it's not displaying that list



On Thu, Dec 21, 2017 at 3:05 PM, Ruhail Ahmad <ruhailahmad9@gmail.com> wrote:
def resturant_listview(request):
template_name = 'resturants/resturants_list.html'
queryset     = ResturantLocation.objects.all()
context        = {
                   "obj_list": queryset
                   }
return render(request,template_name,context)

class ResturantListView(ListView):
template_name   = 'resturants/resturants_list.html'
queryset        =  ResturantLocation.objects.all()

 
{% block content %}

<h1>Resturants List</h1>
<ul>
{% for obj in obj_list %}
<li>{{obj.name}} {{obj.location}} {{obj.category}} {{obj.timestamp}}</li><hr>
{% endfor %}
</ul>
{% endblock content %}


It's because ListView makes available the queryset to the template in the "object_list" variable, and your template is expecting "obj_list" which you provide in your FBV

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BFDnh%2BiqLO%3DBXt4wg1Q9v5FoMAGoxnzjZLtihVE8x4JHzAePQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment