"Add_prod"라는 클래스가 있는데, 책, 저자, 가격 등과 같은 몇 가지 열을 만들었습니다. 템플릿에서 가격을 오름차순/내림차순으로 정렬 할 수있는 두 개의 하이퍼 링크를 만들었습니다. "name "속성은 앵커 태그에서 지원하지 않습니다. 또한 이름 대신 id 속성을 사용했지만 여전히 사용하지 않았습니다. 정렬 된 순서로 제품을 정렬하도록 앵커 태그에서 데이터를 가져 오는 방법은 다음과 같습니다.django의 링크 태그에서 데이터를 가져 오는 방법은 무엇입니까?
Views.py,
def welcome_user(request):
if 'low_price' in request.GET:
my_products = Add_prod.objects.all().order_by('price')
elif 'high_price' in request.GET:
my_products = Add_prod.objects.all().order_by('-price')
else:
my_products = Add_prod.objects.all()
context = { "Products":my_products}
#rest of code for other functionalities
return render(request,"welcome-user.html",context)
내 템플릿 파일,
<form>
<div style="text-align: right">
<a name="low_price" href="{% url 'welcome_user' %}">Low Price</a>
<a name="high_price" href="{% url 'welcome_user' %}">High Price</a>
</div>
</form>
당신은'url' 태그에 매개 변수를 제공해야합니다. – Wtower