Ad
Get Query String Variable Name In Django
I am new to Django, so my problem might be simple. I need to write a template, that would echo information from a query string. The string looks something like that: http://127.0.0.1:8000/echo/?a=1 The problem is, that query name might change from 'a' to something else, and I need to echo it accordingly. I know how to capture value from that string, but I don't know how to capture name. Please help.
def echo(request):
return render(request, 'echo.html', context={
'get': request.GET.get('a'),
'post': request.GET.get('b')
})
<!--DOCTYPE html -->
<html>
<body>
{% if request.method == 'GET' %}
<h1> get a= {{ get }} statement is empty </h1>
{% elif request.method == 'POST' %}
<h2> post b= {{ post }} statement is empty</h2>
{% endif %}
</body>
</html>
Ad
Answer
You could use HttpRequest.META
request.META['QUERY_STRING']
docs:
QUERY_STRING – The query string, as a single (unparsed) string.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad