Skip to content

Commit

Permalink
fix: Add proper headers to the templates return types (#427)
Browse files Browse the repository at this point in the history
* fix: Add proper headers to the templates return types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
sansyrox and pre-commit-ci[bot] authored Feb 20, 2023
1 parent 86ee0e2 commit b8a95ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from robyn.logger import Colors, logger
from robyn.processpool import run_processes
from robyn.responses import jsonify, serve_file, serve_html
from robyn.robyn import FunctionInfo
from robyn.robyn import FunctionInfo, Response
from robyn.router import MiddlewareRouter, Router, WebSocketRouter
from robyn.types import Directory, Header
from robyn.ws import WS
Expand Down Expand Up @@ -309,4 +309,4 @@ def inner(handler):
return inner


__all__ = ["Robyn", "jsonify", "serve_file", "serve_html"]
__all__ = ["Robyn", "jsonify", "serve_file", "serve_html", "Response"]
4 changes: 2 additions & 2 deletions robyn/robyn.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Callable, Optional
from typing import Callable, Optional, Union

class SocketHeld:
def __init__(self, url: str, port: int):
Expand All @@ -19,7 +19,7 @@ class FunctionInfo:
class Response:
status_code: int
headers: dict[str, str]
body: bytes
body: Union[str, bytes]

def set_file_path(self, file_path: str):
pass
Expand Down
13 changes: 10 additions & 3 deletions robyn/templating.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from abc import ABC, abstractmethod

from .robyn import Response

from jinja2 import Environment, FileSystemLoader


Expand All @@ -8,7 +10,7 @@ def __init__(self):
...

@abstractmethod
def render_template(self, *args, **kwargs):
def render_template(self, *args, **kwargs) -> Response:
...


Expand All @@ -20,8 +22,13 @@ def __init__(self, directory, encoding="utf-8", followlinks=False):
)
)

def render_template(self, template_name, **kwargs):
return self.env.get_template(template_name).render(**kwargs)
def render_template(self, template_name, **kwargs) -> Response:
rendered_template = self.env.get_template(template_name).render(**kwargs)
return Response(
status_code=200,
body=rendered_template,
headers={"Content-Type": "text/html; charset=utf-8"},
)


__all__ = ["TemplateInterface", "JinjaTemplate"]

0 comments on commit b8a95ff

Please sign in to comment.