最近我一直在尝试使用 Flask 应用程序和 Github 页面创建一个个人网站。一旦创建了一个名为 .github.io 的存储库并放置了一个名为 index.html 的文件,它将出现在地址 .github.io 上。然而,一旦这个文件被删除并替换为基本的 Flask 应用程序,就会出现 404 页面。
要让 Flask 应用程序在 Github 页面上运行需要什么?
您无法在 Github 页面上托管 Python 应用程序,它是为简单的静态文件托管而设计的。您可以使用 Flask-Frozen 之类的工具将 Flask 应用程序转换为静态页面,但是根据您网站的功能,您显然需要进行一些重大权衡。
也许如果你在index.html文件中配置javascript来运行flask项目,它可能会起作用
像这样
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class RunFlaskApp {
public static void main(String[] args) {
try {
// Command to run Flask application
String command = "python -m flask run --app board --debug";
// Execute the command
Process process = Runtime.getRuntime().exec(command);
// Read the output of the command
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// Wait for the process to complete
process.waitFor();
// Close the reader
reader.close();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}