Get the Parameter Value From URL

231 views
Skip to first unread message

Pravin Yadav

unread,
Jun 12, 2018, 8:49:31 AM6/12/18
to django...@googlegroups.com
Hello,

I want to get the parameter value from url in djago template. i'm using the django 2.0.6 and python 3.6.1.

base.html:-  

{{ request.GET.get('videorandom_id') }}
 


Error Message:

TemplateSyntaxError at /watch/videos/4626634807531689

Could not parse the remainder: '('videorandom_id')' from 'request.GET.get('videorandom_id')'

Request Method: GET
Django Version: 2.0.6
Exception Type: TemplateSyntaxError
Exception Value:

Could not parse the remainder: '('videorandom_id')' from 'request.GET.get('videorandom_id')'

Exception Location: /usr/local/lib/python3.6/site-packages/django/template/base.py in __init__, line 668
Python Executable: /usr/local/bin/python3
Python Version: 3.6.1
Python Path:

['/var/www/html/videowithfriends',
 '/usr/local/lib/python36.zip',
 '/usr/local/lib/python3.6',
 '/usr/local/lib/python3.6/lib-dynload',
 '/usr/local/lib/python3.6/site-packages']

Server time: Tue, 12 Jun 2018 12:46:13 +0000




赖信桃

unread,
Jun 13, 2018, 7:16:18 AM6/13/18
to django...@googlegroups.com
Hi, Pravin

You don't need `get` method in template, just use dot, and if it doesn't exist, Django template engine will set it to None automatically.

Both below works:

```
{{ request.GET.foo }}

{% if request.GET.my_var %}
  {{ request.GET.my_var }}
{% endif %}
```


Pravin Yadav <pk.j...@gmail.com>于2018年6月12日周二 下午8:49写道:
--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEr6%3DdxutOMOROR_xjjA%3DYs%2BA2PHGA0KrbFeXxu%2BY-YVmeyc4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages