admin管理员组

文章数量:1025477

I want to write an online store using django and javascript, where javascript is only for decoration. You need to implement categories and several subcategories in subcategories. In theory, "django-mptt" is well suited for this (.html ). We build a tree of categories and subcategories, display a link to the product slug, and everything works well. But only the last category and the product name are displayed in the address bar, and I want the full path. I take "django-mptt-urls" as a basis ( ) there, "Photo" is used as the final object. We are building a path based on the Category model, and a list of end objects in "templates/gallery/category" {% for photo in instance.photos.all%} is available in the subcategory. There is a problem when you try to display the Photo model on a separate page in a separate DetailView:

  1. I create absolute_path using instance.get_absolute_url and photo.slug to the desired page, we don't have absolute_path in the Photo table. Is it even possible to display the desired page in this way?
  2. Having received absolute_path in the url, django first reads it as a category r'^gallery/(?P.*)$'. How to differentiate the paths?

we get the absolute path in template:

{% for photo in instance.photos.all %}
<li>{{ photo.name }}
{% with final_path=instance.get_absolute_url|add:'/'|default:'' %}
{% if final_path %}
{% with final_path|slice:"1:" as sliced_path %}
<a href="{% url 'object' sliced_path|add:photo.slug %}">{{ photo.name }}</a>
{% endwith %}
{% else %}
{{ photo.name }}
{% endif %}
{% endwith %}

I want to write an online store using django and javascript, where javascript is only for decoration. You need to implement categories and several subcategories in subcategories. In theory, "django-mptt" is well suited for this (.html ). We build a tree of categories and subcategories, display a link to the product slug, and everything works well. But only the last category and the product name are displayed in the address bar, and I want the full path. I take "django-mptt-urls" as a basis ( ) there, "Photo" is used as the final object. We are building a path based on the Category model, and a list of end objects in "templates/gallery/category" {% for photo in instance.photos.all%} is available in the subcategory. There is a problem when you try to display the Photo model on a separate page in a separate DetailView:

  1. I create absolute_path using instance.get_absolute_url and photo.slug to the desired page, we don't have absolute_path in the Photo table. Is it even possible to display the desired page in this way?
  2. Having received absolute_path in the url, django first reads it as a category r'^gallery/(?P.*)$'. How to differentiate the paths?

we get the absolute path in template:

{% for photo in instance.photos.all %}
<li>{{ photo.name }}
{% with final_path=instance.get_absolute_url|add:'/'|default:'' %}
{% if final_path %}
{% with final_path|slice:"1:" as sliced_path %}
<a href="{% url 'object' sliced_path|add:photo.slug %}">{{ photo.name }}</a>
{% endwith %}
{% else %}
{{ photo.name }}
{% endif %}
{% endwith %}

本文标签: