错误:404 Not Found 抱歉,请求的 URL 'http://localhost:8000/main.html' 导致错误:文件不存在

Ali*_*464 0 html javascript python weather eel

在此输入图像描述 Everythink 进展顺利,但是当我完成代码并尝试运行时,我收到了此错误,您认为会发生什么。我使用 Linux Mint。我认为问题出在 EEL 模块上,当我运行 html 代码并转到控制台时,我可以看到GET file:///eel.js net::ERR_FILE_NOT_FOUND 我已经解决这个问题 3-4 天了,但我找不到答案。我希望你能帮助我解决这个问题。Python代码:

import eel
import pyowm


own = pyowm.OWM('d845c8640738fe82515cb1277bb3dd38')

eel.init('web')

eel.start('main.html', size=(700, 700))

@eel.expose
def get_weather(city):

    mgr = own.weather_manager()

    observation = mgr.weather_at_place(city)
    w = observation.weather 

    temp = w.temperature('celsius')['temp']

    return city + ' ' +  str(temp)
Run Code Online (Sandbox Code Playgroud)

和 html/js 代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Weather</title>


    <script type="text/javascript" src="/eel.js"></script>
    <link rel="stylesheet" type="image/png" href="weather-icon.png">
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

    <input id="location" type="text" placeholder="Write the name of your Country ot City" required="" value="Bukhara, Uzbekistan">

    <button id ="show">Know the weather</button>

    <div id="info">


        
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">

        async function display_weather(){
            let place = document.getElementById('location').value;

            let res = await eel.get_weather(place)();
            document.getElementById('info').innerHTML = res;
        }

        jQuery('#show').on('click', function(){
            display_weather();
        });

    </script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在我询问并指出我在浏览器控制台中看到的第二个错误之前,不幸的是我找不到答案。谢谢

jcp*_*uas 5

我已经遇到了同样的问题并且能够解决。我解决的方法就是更改行:

eel.init('web')

这样它就使用绝对路径,比如

eel.init('C:/.../web')其中“C:/.../web”是我的 Web 文件夹的当前位置

如果您想搜索更多相关信息,我推荐这篇文章: https: //github.com/samuelhwilliams/Eel/issues/168 但更改路径对我有用