Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1737

Flask frontend is working properly, however the svelte app inside is not, what am I missing

$
0
0

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.


Viewing all articles
Browse latest Browse all 1737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>