queryser variable from template to a view

13 views
Skip to first unread message

Luca Bertolotti

unread,
Sep 18, 2019, 8:52:54 AM9/18/19
to Django users
Hello i need to pass a query set from template to a view:

<a href="/test/group/{{ data }}">

in which way i have to define the urls file

path('test/<slug:valore>/***what to write+++', views.test, name='test'),

Jani Tiainen

unread,
Sep 18, 2019, 9:56:19 AM9/18/19
to django...@googlegroups.com
Hi.

<str:myvar> to the rescue!

Also it is recommended to use {% url %} tag to construct urls not to hardcode them and once were there Django convention is to end urls to slash.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ad42877-766c-49b9-af51-e67007af80f9%40googlegroups.com.

Luca Bertolotti

unread,
Sep 18, 2019, 12:32:11 PM9/18/19
to Django users
Hello
if i pass <str:myvar>
and in the view i do this

def exmple(request,myvar):
      sort = myvar.order_by(........)
i get an error because myvar is a string instead i near a query set

Luca


Il giorno mercoledì 18 settembre 2019 15:56:19 UTC+2, Jani Tiainen ha scritto:
Hi.

<str:myvar> to the rescue!

Also it is recommended to use {% url %} tag to construct urls not to hardcode them and once were there Django convention is to end urls to slash.

ke 18. syysk. 2019 klo 15.53 Luca Bertolotti <luca72.b...@gmail.com> kirjoitti:
Hello i need to pass a query set from template to a view:

<a href="/test/group/{{ data }}">

in which way i have to define the urls file

path('test/<slug:valore>/***what to write+++', views.test, name='test'),

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Jani Tiainen

unread,
Sep 18, 2019, 2:22:34 PM9/18/19
to django...@googlegroups.com
Well that is the side-effect of capturers they convert value to desired format. 

You can find documentation about pre-defined converters and how to register your own at https://docs.djangoproject.com/en/2.2/topics/http/urls/#path-converters


ke 18. syysk. 2019 klo 19.33 Luca Bertolotti <luca72.b...@gmail.com> kirjoitti:
Hello
if i pass <str:myvar>
and in the view i do this

def exmple(request,myvar):
      sort = myvar.order_by(........)
i get an error because myvar is a string instead i near a query set

Luca

Il giorno mercoledì 18 settembre 2019 15:56:19 UTC+2, Jani Tiainen ha scritto:
Hi.

<str:myvar> to the rescue!

Also it is recommended to use {% url %} tag to construct urls not to hardcode them and once were there Django convention is to end urls to slash.

ke 18. syysk. 2019 klo 15.53 Luca Bertolotti <luca72.b...@gmail.com> kirjoitti:
Hello i need to pass a query set from template to a view:

<a href="/test/group/{{ data }}">

in which way i have to define the urls file

path('test/<slug:valore>/***what to write+++', views.test, name='test'),

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ad42877-766c-49b9-af51-e67007af80f9%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22af4b9c-839d-4d8a-ab73-94c2f6c72466%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages