-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make displaying images from widgets work with flask
- Loading branch information
Showing
7 changed files
with
35 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import base64 | ||
import os | ||
|
||
from flask import render_template_string | ||
from flask import Flask, render_template_string, send_from_directory | ||
|
||
from happyMirror.render import BaseRenderer, RenderResult | ||
|
||
|
||
class Renderer(BaseRenderer): | ||
def render(self) -> RenderResult: | ||
image = '/' + os.path.dirname(os.path.relpath(__file__)) + '/images/01.png' | ||
print(image) | ||
|
||
return { | ||
'view': render_template_string('<img src="{{ image }}" />', image=image) | ||
} | ||
def register_custom_routes(self, app: Flask): | ||
print(f"Widget '{__name__}' is registering custom routes...") | ||
app.add_url_rule( | ||
'/widgets/simple_image/images/<path:image_file>', view_func=self.send_image | ||
) | ||
|
||
def send_image(self, image_file): | ||
image_dir = os.path.dirname(os.path.relpath(__file__)) + '/images' | ||
return send_from_directory(image_dir, image_file) | ||
|
||
def render(self) -> RenderResult: | ||
image = '/' + os.path.dirname(os.path.relpath(__file__)) + '/images/640px-Youngkitten.jpg' | ||
return { | ||
'view': render_template_string('<img src="{{ image }}" />', image=image) | ||
} |