模板中的多个视图

时间:2019-04-03 07:57:33

标签: django-models django-templates django-views

在Django中,product.html页面扩展了base.html页面,base.html页面具有菜单列表。谁的值在Product模型的HompeListView的home.html中定义,并且在product.html页面的内容中我想详细查看产品模型。因此,总而言之,我既要在product.html中同时使用产品的listview和detailview,又该如何做呢? 用于从产品字段填充菜单的ListView, 在Content DetailView中用于显示选定的产品详细信息

我的Views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.urls import reverse_lazy
from django.views.generic import (View, TemplateView, DetailView, ListView,
                                    CreateView)

class ProductListView(ListView):
    context_object_name = 'home'
    model = models.Products
    template_name = home.html

class HomeListView(indexlistview):
    context_object_name = 'home'
    model = models.Products
    template_name = 'home.html'


class ProductDetailView (DetailView):
    context_object_name = 'pdetail'
    model = models.Products
    template_name = 'product.html'

我的home.html

{% extends "base.html" %}
{% load staticfiles %}
<!DOCTYPE html>
{% block content_block %}

<div class="content">
  <!-- Start: slider -->
  <div class="slider">
      <div class="container-fluid">
          <div id="heroSlider" class="carousel slide">
              <div class="carousel-inner">

                  {% for Products in home %}
                  <div class="item">
                      <div class="hero-unit">
                          <div class="row-fluid">
                              <div class="span7 marketting-info">
                                  <h1>{{Products.p_name}}</h1>
                                  <p>
                                      {{Products.p_sh_dtl}}
                                  </p>
                                  <h3>
                                      <a href="{% url 'Products' pk=Products.pk %}" class="btn">Learn more</a>
                                  </h3>
                              </div>
                              <div class="span5">
                                  <img src="{{Products.pimage_sm.url}}" class="thumbnail">
                              </div>
                          </div>
                      </div>
                  </div>

                  {% endfor %}

我的product.html

{% extends "home.html" %}
{% load staticfiles %}
<!DOCTYPE html>
{% block content_block %}


<div class="content">
  <div class="container">
    <!-- Start: Product description -->
    <airticle class="article">
      <div class="row bottom-space">
        <div class="span12">
          <div class="page-header">

            <h1>{{pdetail.p_name}}<small>{{pdetail.p_slogan}}</small></h1>
          </div>
        </div>
        <div class="span12 center-align">
          <img src="{{pdetail.pimage_lg.url}}" class="thumbnail product-snap">
        </div>
      </div>
      <div class="row">
        <div class="span10 offset1">
          <p>{{product_ko_detail.p_lg_dtl}}
          </p>
          <div class="span8 offset1">
            <h3>Features of {{ pdetail.p_name }}</h3>
            <ul class="features">
              <li>
                <i class="icon-ok "></i> {{pdetail.condition1}}
              </li>
              <li>
                <i class="icon-ok "></i>{{pdetail.condition2}}.
              </li>
              <li>
                <i class="icon-ok "></i>{{pdetail.condition3}}.
              </li>
              <li>
                <i class="icon-ok "></i>{{pdetail.condition4}}.
              </li>
              <li>
                <i class="icon-ok "></i>{{pdetail.condition5}}.
              </li>
            </ul>
          </div>
        </div>
      </div>
    </airticle>
    <!-- End: Product description -->
  </div>
</div>
{% endblock %}

我想要产品的菜单列表作为下拉菜单,来自home.html,从home.html选择项目后,我希望在product.html中有详细信息。我说的是详细信息,但是在product.html中我无法获得来自home.html或base.html的产品列表。那我怎么得到这个?请帮助我

0 个答案:

没有答案