【发布时间】:2020-08-23 20:22:50
【问题描述】:
在尝试构建我的第一个 django 项目时,我被困在传递值以进行产品过滤。每个传递给它的值为 1 的特征将是一个活动过滤器,而其他的将是 0,即不活动。 urls.py:
urlpatterns=[
path('women/<str:category>/filter?pricefrom=<int:min>&to=<int:max>&size?s=<int:s>&m=<int:m>&l=<int:l>&xl=<int:xl>&xxl=<int:xxl>&xxxl=<int:xxxl>&color?blue=<int:blue>&red=<int:red>&yellow=<int:yellow>&black=<int:black>&white=<int:white>&green=<int:green>&brown=<int:brown>',views.women_category,name='women category page with filters'),
]
views.py:
def women_category(request,category,id=None,flag=None,min=None,max=None,s=None,m=None,l=None,xl=None,xxl=None,xxxl=None,blue=None,red=None,yellow=None,black=None,white=None,green=None,brown=None):
#product filter logics here
我希望用户应该能够使用任何可能的过滤器组合,过滤器是: 价格:最低,最高 尺码: S,M,L,XL,XXL,XXXL 颜色:黄色,蓝色,绿色,...等
我不知道如何在 urls 中使用 Regex,所以请帮我将我的 url 转换为 regex url,以便所有过滤器变量都是可选的,可以通过前端传递。
【问题讨论】:
标签: python django regex e-commerce django-urls