Open possnfiffer opened 2 years ago
Actually trying render_partial first to see if that solves it
Ok, so I have
html = chameleon_partials.render_partial("videos/partials/search_results.pt", videos={"videos": vm.videos}, search_text=vm.search_text)
working to render the HTML but now I have to figure out how to properly return that and have it load in my #search-results div
fastapi_chameleon.exceptions.FastAPIChameleonException: Invalid return type <class 'chameleon_partials.HTML'>, we expected a dict or fastapi.Response as the return value.
That's what I get if I return the HTML object.
I'm working on figuring out what needs to be returned. I have tried something different variations of the following like:
model = json.dumps(html.html_text)
return fastapi.responses.HTMLResponse(status_code=status.HTTP_200_OK, content=model)
I'm getting somewhere though, that's good.
I guess this whole discussion should really fit in the new GitHub Discussions section rather than Issues
html = chameleon_partials.render_partial("videos/partials/search_results.pt", videos=vm.videos, search_text=vm.search_text)
return fastapi.responses.HTMLResponse(status_code=status.HTTP_200_OK, content=html.html_text.encode('utf-8'))
This is what I have that's working. PyCharm is complaining about vm.videos. It says "Expected type 'dict', got 'list[Video] | None' instead"
After all this, now that I think about it, this is essentially a feature request. If there were something like from fastapi.templating import Jinja2Templates
that works similar to the Jinja one but for chameleon that would be cool then there could be a blurb about it up on the FastAPI Docs page
I'm trying to build a video collector similar to the one from your HTMX course. Mine uses FastAPI, Chameleon, Beanie. I'm having trouble rendering the search results due to the conditional partial render inside of the view method. I don't know how to render a template when it's inside the view method like that, only done it through the decorator on the view method function itself.
How would I implement something like this in fastapi-chameleon?
I have tried the following with
from fastapi_chameleon import template
importedI also tried getting creative and reading through your fastapi-chameleon source, so I tried
That didn't work either.
At the moment I'm going to try following the FastAPI docs If I have to for now I'll do just this one partial using Jinja if I can get it to do that.. we'll see. I appreciate any help or suggestions you may have on this. I'll definitely submit this webapp I'm working on to the Student Creation Showcase once it's ready enough and is actually doing interesting things.