Fetch doctype child table and show in HTML JINJA

Hi Expert,

Anyone had experience to fetch the doctype child table from python (py) which store in a.py file.
main doctype name → Main Doc (table link name to child table = childT)
child doctype name → Child Doc

Then to fetch the the content of the Child Doc base on the selection of the Main Doc doctype ?
The result should shown in another file name b.html

Can anyone help to provide the logic code ? Should I using JINJA code in HTML or other method ?
Please advice.

Thanks.

You can use some thing like this

@frappe.whitelist()
def get_patient_encounter_data(**kwargs):
	data = frappe._dict(kwargs)
	try:
		encounter_data = frappe.get_all("Patient Encounter", filters={"name":data.get("name")},
		fields=["name",])
		for row in encounter_data:
			encounter_doc = frappe.get_doc("Patient Encounter",row.name)

			exercise = []
			for exercise_row in encounter_doc.exercise:
				exercise.append(dict(
					joints = exercise_row.joints,
					exercise_type = exercise_row.exercise_type,
					exercise_name = exercise_row.exercise_name,
					repetition_per_session = exercise_row.repetition_per_session,
					frequency_per_day = exercise_row.frequency_per_day,
					no_of_days = exercise_row.no_of_days,
					youtube_url = exercise_row.youtube_url
				))
			row["exercise"] = exercise

		return (200,"Patient Encounter Data Successfully",encounter_data)
	except Exception as e:
		frappe.log_error(frappe.get_traceback())
		return (500,"Something Wrong. Please Try Again")