-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return html in flask-restful #529
Comments
|
There's a method _endpoint_templates = {
'main.index': 'index.html',
'user.profile': 'profile.html',
'default': 'default.html'
}
@api.representation('text/html')
def render_endpoint_template(data, code, headers):
template = _endpoint_templates.get(request.endpoint, _endpoint_templates['default'])
return render_template(template, **data), code, headersPretty low tech, but I'd imagine it'd go a fair distance. You'd probably want some way of automatically associating templates with endpoints so you're not constantly having to update the dictionary. |
|
@justanr's solution would probably work (though it's probably not very robust). I think you could also return a Either way, Flask-RESTful isn't the tool you want to use for rendering webpages. |
|
I could see a use case for returning HTML or JSON or something else depending on the |
how can i return html directly in flask-restful. For example, my index.html is in /xxx/index.html, and how can i make a response to return the html directly not use render_template.
The text was updated successfully, but these errors were encountered: