Answer the question
In order to leave comments, you need to log in
How to get json of whole page?
Good day.
Tell me how to get any url in django as json?
Let's say we add ?template=1 to any url at the end
so that it displays something like this
{
"template": "<div>тут мой шаблон</div>"
}
Answer the question
In order to leave comments, you need to log in
If you need the whole view, then you can do it like this, but here you are not passing the name of the template, but the URL
from django.test import Client
client = Client()
response = client.get('/')
content = response.content
from django.template.loader import get_template
template = get_template('my_template.html')
result = template.render({'var': 'test'})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question