Please check this page.
What is the SQL ''LIKE" equivalent on Django ORM queries?
That’s Django’s ORM way.
https://docs.djangoproject.com/en/4.2/topics/db/sql/
This is how Django handles raw queries.
>>> query = "SELECT * FROM myapp_person WHERE last_name = %s" % lname >>> Person.objects.raw(query)
What you are showing is not Django code, but pure Python-MySQL code.
For Python-MySQL you can do it the way you did and it will handle quotes and injection issues.
But you should.
title_like = f"%{title}%" cursor.execute(query, (title_like,))
title_like is a fuzzy matching string.