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

问题描述

enter image description here

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)

和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>

在我询问并仅指出我在浏览器控制台中看到的第二条错误提示之前,不幸的是我找不到该请求。 谢谢

解决方法

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

eel.init('web')

以便它使用绝对路径,例如

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

如果您想搜索更多有关该文章的信息,我建议您:https://github.com/samuelhwilliams/Eel/issues/168 但改变道路对我有用