【问题标题】:Error: 404 Not Found Sorry, the requested URL 'http://localhost:8000/main.html' caused an error: File does not exist错误:404 Not Found 抱歉,请求的 URL 'http://localhost:8000/main.html' 导致错误:文件不存在
【发布时间】:2022-01-23 09:49:04
【问题描述】:

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>

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

【问题讨论】:

    标签: javascript python html weather eel


    【解决方案1】:

    我已经遇到了同样的问题,我能够解决。我解决的方法就是换行:

    eel.init('web')

    使其使用绝对路径,如

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

    如果你想搜索更多关于它的信息,我推荐这个帖子:https://github.com/samuelhwilliams/Eel/issues/168 但改变路径对我有用

    【讨论】:

    • “我的网络文件夹在哪里......” - 请通过提供您将提供的内容来完成句子。
    • 我的意思是路径('C:/.../web')是我的 web 文件夹的位置。
    【解决方案2】:

    刚刚遇到这个问题,我已经用它以更通用的方式解决了:

    import os
    
    eel.init(f'{os.path.dirname(os.path.realpath(__file__))}/web')
    

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 2015-01-14
      • 2022-01-21
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 2017-01-20
      • 2019-12-10
      相关资源
      最近更新 更多