英文:
objects titles are not passing to dropdown in multiple pages
问题
I created a navbar for each page and I want to include a dropdown by passing the model object title to the list. It's passing to the main page but not passing to other pages.
My template:
<li class="menu-has-children"><a href="#services">All Services</a>
<ul style="display: inline;">
{% for detailinfo in detail.all %}
<li><a href="{% url 'details' services.slug %}">{{ detailinfo.title }}</a></li>
{% endfor %}
</ul>
</li>
My view:
def details(request, services_slug):
q = services.objects.filter(slug=services_slug)
if q.exists():
q = q.first()
else:
return HttpResponse("<h1>Page not found</h1>")
detail = {'detail': q}
return render(request, 'detail.html', detail)
And this is my main page view. It passes the titles to it but not to the detail page.
My main page view:
def homepage(request):
aboutinfo = aboutpage.objects
servicesinfo = services.objects
programinfo = prgm.objects
return render(request, 'index.html', {'aboutinfo': aboutinfo, 'servicesinfo': servicesinfo, 'programinfo': programinfo})
(Note: I've removed the HTML escaping for better readability, but you should make sure to include it in your actual code if needed.)
英文:
i created nav bar for ea ch pages and i want include a dropdown by passing model object title to the list
and its passing to main page but not passing to other pages
my template
<li class="menu-has-children"><a href="#services">All Services</a>
<ul style="display: inline;">
{% for detailinfo in detail.all %}
<li><a href="{% url 'details' services.slug %}">{{ detailinfo.title }}</a></li>
{% endfor %}
</ul>
</li>
my view
def details(request, services_slug):
q = services.objects.filter(slug=services_slug)
if q.exists():
q=q.first()
else:
return HttpResponse("<h1> page not found </h1>")
detail = {'detail': q}
return render(request, 'detail.html', detail,)
and my this is my main page view it passed the titles in it but not in the detail
my main page view
def homepage(request):
aboutinfo = aboutpage.objects
servicesinfo = services.objects
programinfo = prgm.objects
return render(request, 'index.html', {'aboutinfo': aboutinfo, 'servicesinfo': servicesinfo,
'programinfo': programinfo})
答案1
得分: 1
你需要在对象后面添加 .all() 来检索所有对象。
servicesinfo = services.objects.all()
英文:
you have to add .all() after the object to retrieve all objects
servicesinfo= services.objects.all()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论