简体   繁体   English

如何在Django 2.0中访问下一页

[英]How I can access to the next page in django 2.0

I have the following scenery. 我有以下风景。 In the first page there are type of products, when choose specific type it sends to the page of products of the specific type, then when I choose the product it should send me to the page of the product where there is full information about the product. 在第一页中,有产品类型,当选择特定类型时,它将发送到特定类型产品的页面,然后,当我选择产品时,应将我发送到具有产品完整信息的产品页面。 But I can't access the last product page. 但是我无法访问上一个产品页面。 How I should fix this? 我该如何解决? My code: 我的代码:

views.py: views.py:

def products_fizlitso(request):

 fizlitso_product = InsuranceProducts.objects.filter(product_type="Физическое 
 Лицо")

 context = {'fizlitso_product': fizlitso_product}
 return render(request, 'insurance_products/fizlitso/fizlitso.html', context)


def fizlitso_type(request, type_id):

 product_type = get_object_or_404(InsuranceProducts, id=type_id)

 context = {'product_type': product_type}
 return render(request, 'insurance_products/fizlitso/fizlitso_type.html', 
 context)

def product_page(request, product_id):

 product = get_object_or_404(ProductType, id=product_id)

 context = {'product': product}
 return render(request, 'insurance_products/fizlitso/product.html', context)

here is the urls.py: 这是urls.py:

# ******************************************************************
path('fizlitso/', views.products_fizlitso, name='product_fizlitso'),
# ******************************************************************

# ******************************************************************
path('fizlitso/product_type<int:type_id>', views.fizlitso_type, name='fizlitso_type'),
# ******************************************************************

# ******************************************************************
path('fizlitso/product_type<int:type_id>/product<int:product_id>', views.product_page, name='product_page'),
# ******************************************************************

and here is the django part of the template which holds all the product types: 这是模板的django部分,其中包含所有产品类型:

  {% for product in fizlitso_product %}
  <div class="btmspace-80">
    <h3>{{ product.product_area }}</h3>
    <img class="imgr borderedbox inspace-5" src="{% static 'img/imgr.gif' %}" alt="">
    <p>
        {{ product.product_description }}
    </p>

    <p>
        Подробно вы можете узнать <a href="{% url 'main:fizlitso_type' product.id %}">здесь</a></a>
    </p>
  </div>
  {% endfor %}

And here the django part of the template which holds all the products of the specific type: 这是模板的django部分,其中包含特定类型的所有产品:

  {% for product in product_type.producttype_set.all %}
  <div class="btmspace-80">
    <h3>{{ product.title }}</h3>
    <img class="imgr borderedbox inspace-5" src="{% static 'img/imgr.gif' %}" alt="">
    <p>
        {{ product.description }}
    </p>

    line 84  <p>
      Подробно вы можете узнать <a href="{% url 'main:product_page' product.id %}">здесь</a></a>
    </p>
  </div>
  {% endfor %}

And here is the page about the specific product chosen from above page: 这是有关从上一页选择的特定产品的页面:

    <div class="btmspace-80">
    <h3>{{ product.title }}</h3>
    <img class="imgr borderedbox inspace-5" src="{% static 'img/imgr.gif' %}" alt="">
    <p>
        {{ product.description }}
    </p>
  </div>

And this one is the error: 而这是错误:

NoReverseMatch at /fizlitso/product_type1 / fizlitso / product_type1上的NoReverseMatch

Reverse for 'product_page' with arguments '('',)' not found. 找不到带有参数“('',)”的“ product_page”。 1 pattern(s) tried: ['fizlitso\\/product_type(?P[0-9]+)\\/product(?P[0-9]+)$'] 尝试了1个模式:['fizlitso \\ / product_type(?P [0-9] +)\\ / product(?P [0-9] +)$']

C:\\Users\\Lenovo 101\\PycharmProjects\\uzagro_3\\main\\templates\\insurance_products\\fizlitso\\fizlitso_type.html, error at line 84 C:\\ Users \\ Lenovo 101 \\ PycharmProjects \\ uzagro_3 \\ main \\ templates \\ insurance_products \\ fizlitso \\ fizlitso_type.html,第84行错误

your url name product_page have two parameters:type_id,product_id 您的网址名称product_page有两个参数:type_id,product_id

path('fizlitso/product_type<int:type_id>/product<int:product_id>', views.product_page, name='product_page')

you give one? 你给一个?

<a href="{% url 'main:product_page' product.id %}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM