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:
- 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?
- 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:
- 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?
- 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 %}
本文标签:
版权声明:本文标题:python - Is it possible to implement a DetailView of an object model in django-mptt-url categories using the absolute path of th 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745622963a2159688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论