Home > Blockchain >  Django, remove the querystring from a url string
Django, remove the querystring from a url string

Time:01-12

Good day all. I've to modify a string in a template that use Django. the string is a URL, but this can contain a querystring, so basically the url could be:

"www.test.com/something" or
"www.test.com/something?page=2"

I'd like to remove the "?page=2" from the url, in javascript I'd do something like

urlString.split("?")[0];

is there any similar solution in django? I can only access the "frontend" of this site, so I cannot define anything, I can only modify the "templates".

Thanks in advance.

CodePudding user response:

With python (Django is Python) it's nearly the same syntax.

Just without the semicolon at line end.

The variable name urlString could also be used but its a soft standard to write snake cased object variables.

url_string = 'www.test.com/something'
url_string.split('?')[0]


url_string = 'www.test.com/something?page=2'
url_string.split('?')[0]
  •  Tags:  
  • Related