Get the Parameter Value From URL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get the Parameter Value From URL

Pravin Yadav
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




--
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 [hidden email].
To post to this group, send email to [hidden email].
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 | Threaded
Open this post in threaded view
|

Re: Get the Parameter Value From URL

赖信桃
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 <[hidden email]>于2018年6月12日周二 下午8:49写道:
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




--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAMv51WTsjk0JrCJnOUptVXqkXRHUhxSR1HkNMoGNGp2Ssok74A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.