Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Eel.egg-info
*.swp
venv/
.tox
/env
5 changes: 5 additions & 0 deletions eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'port': 8000, # Port used for Bottle server (use 0 for auto)
'block': True, # Whether start() blocks calling thread
'jinja_templates': None, # Folder for jinja2 templates
'jinja_global': None, # Dict with association globalKey -> globalFunction
'cmdline_args': ['--disable-http-cache'], # Extra cmdline flags to pass to browser start
'size': None, # (width, height) of main window
'position': None, # (left, top) of main window
Expand Down Expand Up @@ -153,6 +154,10 @@ def start(*start_urls, **kwargs):
_start_args['jinja_env'] = Environment(loader=FileSystemLoader(templates_path),
autoescape=select_autoescape(['html', 'xml']))

if _start_args['jinja_global'] != None:
for key in _start_args['jinja_global'].keys():
_start_args['jinja_env'].globals[key] = _start_args['jinja_global'][key]


# Launch the browser to the starting URLs
show(*start_urls)
Expand Down
6 changes: 5 additions & 1 deletion examples/06 - jinja_templates/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ def say_hello_py(x):
say_hello_py('Python World!')
eel.say_hello_js('Python World!') # Call a Javascript function

eel.start('templates/hello.html', size=(300, 200), jinja_templates='templates') # Start
def say_hello_jinja(x):
print('Hello from %s' % x)
return ""

eel.start('templates/hello.html', size=(300, 200), jinja_templates='templates', jinja_global={"say_hello_jinja": say_hello_jinja}) # Start
7 changes: 4 additions & 3 deletions examples/06 - jinja_templates/web/templates/hello.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% extends 'base.html' %}
{% block title %}Hello, World!{% endblock %}
{% block head_scripts %}
{% block head_scripts %}
eel.expose(say_hello_js); // Expose this function to Python
function say_hello_js(x) {
console.log("Hello from " + x);
Expand All @@ -16,12 +16,13 @@
}

eel.py_random()(print_num);

say_hello_js("Javascript World!");
eel.say_hello_py("Javascript World!"); // Call a Python function
{% endblock %}
{% block content %}
Hello, World!
<br />
<a href="page2.html">Page 2</a>
{% set hello = say_hello_jinja("Jinja World!") %}
{% endblock %}