I have been strugling with this example https://github.com/cabreraalex/svelte-flask-example. I created a simpler example hereWhen I run the server.py, I get the template, in the source code I even see the main.js. When I go to /rand I see the randomly generated number, however I am missing something, as I can not get the App.svelte to work.This is what the server.py contains:
@app.route('/home')def base(): return send_from_directory('templates/', 'index.html' )@app.route('/static/<path:path>')def home(path): return send_from_directory('', path)@app.route('/rand')def rand(): return str(randint(0,100))
The index.html has the <script src="../static/main.js" defer></script>
The main JS import the svelte App
import App from './App.svelte'const app = new App({ target: document.querySelector('#svelte-app')})
The Svelte app itself:
<script> let rand = -1 function getRand(){ fetch('./rand') .then(d => t.text()) .then(d => (rand = d)); }</script><h1> your number is: {rand}</h1><button on:click={getRand}>Get a random number</button>
I am brand new to the combination of flask and JS, so I am sorry in advance.