Skip to content

Template context serialization #732

Answered by vitalik
LazerRaptor asked this question in Q&A
Discussion options

You must be logged in to vote

@LazerRaptor

what you need looks like this:

@router.get('/')
def homepage(request):
    return TemplateResponse(request, "homepage.html", {
         'context': HomepageContext(users=User.objects.all()).json()
    })

and add safe to template:

<div x-data="homepage({{ context | safe }})">...</div>

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@LazerRaptor
Comment options

Comment options

You must be logged in to vote
2 replies
@LazerRaptor
Comment options

@baseplate-admin
Comment options

Answer selected by LazerRaptor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants