Когда я запускаю server.py, я получаю шаблон, в исходном коде я даже вижу main.js. Когда я захожу в /rand, я вижу случайно сгенерированное число, однако мне что-то не хватает, так как я не могу заставить App.svelte работать.
Вот что содержит файл server.py:
Код: Выделить всё
@app.route('/home')
def base():
return send_from_directory('templates/', 'index.html' )
@app.route('/static/
')
def home(path):
return send_from_directory('', path)
@app.route('/rand')
def rand():
return str(randint(0,100))
Основной JS импортирует приложение svelte
Код: Выделить всё
import App from './App.svelte'
const app = new App({
target: document.querySelector('#svelte-app')
})
Код: Выделить всё
let rand = -1
function getRand(){
fetch('./rand')
.then(d => t.text())
.then(d => (rand = d));
}
your number is: {rand}
Get a random number
Подробнее здесь: https://stackoverflow.com/questions/711 ... not-what-a
Мобильная версия