No webview tab

При запуске скрипта flask, не появляется вкладка webview

from flask import Flask
from flask import request
from threading import Thread
import time
import requests


app = Flask('')

@app.route('/')
def home():
  return "I'm alive"

def run():
  #app.run(host='0.0.0.0', port=80)
  app.run()

def keep_alive():
  t = Thread(target=run)
  t.start()

Hi @AnatoliiSolomon, welcome to the community!

I’ve translated your title into English so more people can help.

Next time, please send a link to your Repl. I’m not sure which it is, but you have two Repls on your profile with this code.


Привет @AnatoliiSolomon, добро пожаловать в сообщество!

Я перевела ваше название на английский, чтобы больше людей могли помочь.

В следующий раз, пожалуйста, пришлите ссылку на свой Repl. Я не уверен, что это такое, но у вас есть два Repls в вашем профиле с этим кодом.

1 Like
from flask import Flask, request
from threading import Thread

app = Flask(__name__)

@app.route('/')
def home():
    return 'I am alive'

def run():
    app.run()

def keep_alive():
    t = Thread(target=run)
    t.start()

if __name__ == '__main__':
    keep_alive() 

try this

ogey No response = it works so ima go sleep now gn yallz its 2:20am

1 Like

Well actually OP’s importing the file (if you look at his Repls) so __name__ == '__main__' would be False.

:yawning_face: im too sleepy to think about this
slight correction: 2:21am

Welcome to the community @AnatoliiSolomon !

English:
A noticed a few things in your code that should be addressed so you don’t have the same mistake again.

First: quotation marks.
You’ve used non-standard quotation marks (‘’) instead of the usual single (') or double (") ones. Python does not recognize these. Be sure to use the standard ones!

Second: Exposing HTTP server. (and this is related to your problem).
By default, when your Repl exposes an HTTP server, the Webview will automatically open.
You generally need to run your Flask app on host ‘0.0.0.0’ and port 5000, as this is the standard setting in Replit. So, ensure your server is being exposed correctly.

Third: keep_alive().
Make sure the keep_alive is being called!

The code that @idkwhttph provided should fix your problem but be aware of these in the future!


Russian:

Заметил несколько вещей в вашем коде, которые следует исправить, чтобы не допустить таких же ошибок в будущем.

Первое: кавычки.
Вы использовали нестандартные кавычки (‘’) вместо обычных одинарных (') или двойных ("). Python не распознает их. Убедитесь, что используете стандартные кавычки!

Второе: Открытие HTTP-сервера (и это связано с вашей проблемой).
По умолчанию, когда ваш Repl открывает HTTP-сервер, автоматически открывается Webview.
Обычно вам нужно запускать свое приложение Flask на хосте ‘0.0.0.0’ и порту 5000, так как это стандартная настройка в Replit. Убедитесь, что ваш сервер правильно открывается.

Третье: keep_alive().
Убедитесь, что вызывается функция keep_alive!

Код, предоставленный @idkwhttph, должен решить вашу проблему, но имейте в виду эти моменты в будущем!

uncomment (Ctrl/) the app.run(host… line and remove the app.run() line. 0.0.0.0 exposes the port so it can be accessed externally

1 Like

I have one project working and the other not…
Created another account from another computer and still does not work.

from flask import Flask
from flask import request
from threading import Thread
import time
import requests

app = Flask("")

@app.route("/")
def home():
    return "I'm alive"

def run():
    app.run(host="0.0.0.0", port=5000)

def keep_alive():
    t = Thread(target=run)
    t.start()

1 Like

instead of def run(): ... and the keep_alive function, use the following code:

if __name__ == '__main__':
  app.run(host="0.0.0.0", port=5000)

No keep_alive function is needed since your code will directly expose an HTTP port.