django - 无法重定向到类别列表 url - django
问题描述
我不知道如何重定向到类别列表页面,但 url 工作正常我只是无法通过 id 将正确的重定向 url 添加到 href 标记中:(
html
<div class="widget widget-catgs">
<h3 class="widget-title">Categories</h3>
<ul>
{% for cat in category %}
<li>
<a href="**{% url 'category-list' property.category.id %}**" title=""><i
class="la la-angle-right"></i><span>{{ cat.category__title }}</span></a>
<span>{{ cat.category__title__count }}</span>
</li>
{% endfor %}
</ul>
</div>
视图.py
def property_by_category(request, category_id):
property_list = Property.objects.all()
category = get_object_or_404(Category, pk=category_id)
category_list = Property.objects.filter(category=category)
context = {
'category_list': category_list,
'category_name': category,
'property': property_list
}
return render(request, 'property/property-category.html', context)
网址.py
urlpatterns = [
path('', views.property, name='property-page'),
path('details/<int:property_id>', views.property_details, name='property-details'),
path('category/<int:category_id>', views.property_by_category, name='category-list'),
path('add-property/', views.add_property, name='add-property'),
]
我正在学习django,请看一下我的代码。
解决方案
推荐阅读
- amazon-web-services - AWS Cloudformation:安全组无效
- nested - Dash-Plotly:如何从表示互连和嵌套数据的多下拉列表中进行回调?
- javascript - 根据输入更改 React-Select 选项
- xamarin.forms - 从照片 Android Xamarin 中选择图像
- ruby-on-rails - 如何在设计和使用可恢复时将电子邮件设置为可选?
- android - 运行 Junit 5 Android 测试时未解决的参考 jupiter 和 assertTrue
- r - 使用变量来引用数据框列
- c# - 在后面的代码中定义 HelixViewport3D 与在 XAML 中不同吗?
- c# - 如何通过在c#中优先选择内部环境文件夹来从每个子文件夹中读取文件?
- typescript - 使用带有 FlatList 的打字稿的高阶组件问题