#What is %s ?

7 messages · Page 1 of 1 (latest)

verbal tartan
#

So I'm now in tutorial 3
https://docs.djangoproject.com/en/5.0/intro/tutorial03/

In the first views, you can appreciate the usage of "%s" as part of the strings.

When searching for "%" or "%s", it doesn't shows any search result on the website (any idea on how to search for this?).

So I was wondering the usage of "%" and more specially of "%s" both for strings and HttpResponse argument.

foggy acorn
#

Thats actually something from normal python, its another way of formatting strings:
https://docs.python.org/3/tutorial/inputoutput.html#old-string-formatting

import math

print('The value of pi is approximately %5.3f.' % math.pi)
The value of pi is approximately 3.142.

#

In this example from the tutorial

def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)

The string in the HttpResponse is being rendered to "You're looking at question 5." for example (if the question_id would be 5 in my example)

verbal tartan
#

I asked ChatGPT and it says the "s" is for string

#

OK now I'm researching for myself and found stuff on StackExchange

#

Thanks so much