python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.44k stars 587 forks source link

jinja templates can't work #421

Closed hi-Nobody closed 3 years ago

hi-Nobody commented 3 years ago

I have a project made by Jinja, but it doesn't seem to work correctly. I have install Jinja and eel using pip install eel[jinja2]
Cloud you help me solve the problem, thanks The following is my code: PYTHON:

import eel

@eel.expose
def sign_in():
    return 123

eel.init('static')
eel.start('index.html', size=(330,400), disable_cache=True, templates='templates')

templates-index.html:

{% extends "base.html" %}

{% block title %}Nobody{% endblock %}

{% block main %}
<div class="jumbotron">
  SPIK
</div>
<div class="container">
  <div class="row desc">
  <div class="col">
    <h2><i class="fas fa-kiwi-bird"></i>  Test1</h2>
    <p>SPIK</p>
    </div>
  <div class="col">
      <h2><i class="fas fa-smile-wink"></i>  Test2</h2>
    <p>SPIK</p>
    </div>
  <div class="col">
      <h2><i class="fas fa-leaf"></i>  Test3</h2>
    <p>SPIK</p>
    </div>
  </div>
</div>

{% endblock %}

templates-base.html:

<!DOCTYPE html>
<html lang="zh-TW">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Sans+TC&display=swap">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">  

  <style> body {font-family: 'Noto Sans TC', sans-serif;}</style>
  <title>{% block title %}{% endblock %}</title>

</head>
<body>
  <nav>
SPIK
  </nav>
<main>
  {% block main %}{% endblock %}
</main>
<footer>
SPIK
</footer>

  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  {% block script %}{% endblock %}
</body>
samuelhwilliams commented 3 years ago

Hi @hi-Nobody. It looks like the problems is that you're passing templates='templates' to eel.start rather than jinja_templates='templates'. Once I changed that, your code seems to work. Hope that helps! If it doesn't, let me know, and I'll reopen this.

P.S. thanks for including all of the code needed to reproduce :)