Python 3 f string formatting

Total novice here. I was overjoyed when the string formatting in Python 3 was overhauled and formatting became a breeze. Cutting to the chase, I’m going through the Django tutorial on ‘Writing your first app …’ where it walks you through the procedures to add more views to the poll/views.py starting with the following code snippet.

def detail(request, question_id):
return HttpResponse(“You’re looking at question %s.” % question_id)

With nothing to loose, I modified it to use the f string formatting like so.

def detail(request, question_id):
return HttpResponse(f"You’re looking at question {question_id}")

It worked. But before I take this tidbit and ‘assume’ it will continue to work in a ‘real’ app with the complexity of far more imports and views? What type of ‘gotchas’ would I likely see if I continue to deviate from the ‘norm’ the tutorials show to display a view?

I used the search engine here to see if I ran upon any matches, but the results didn’t show me if this had come up before, or rather my query was ill conceived and executed.

Feedback? Thoughts?
I’m hoping a long time forum member isn’t beating the table going ‘Arrg! Not again!’

Doug

1 Like

Nope, no problems with doing it any which way. String formatting is a pretty standard Python feature, Django doesn’t interfere with it at all. Nothing to worry about here.

1 Like

Ken,

Thank you much for the prompt response and information. It’s music to my ears. :star_struck: