簡體   English   中英

如何通過 flask 應用程序訪問 html 頁面,然后從同一 Z319C34606A7D4A9C76 訪問另一個 html 頁面

[英]How can I access html page through flask app and then another html page from the same flask app

我正在開發一個項目,使用 flask 開發它。 I want to link a html page with flask app and whenever the user click on register button of html page, I want that it redirect user to another html page through flask app. 我怎樣才能做到這一點?

例如,使用 Nginx 托管兩個使用 uwsgi Nginx 配置的 flask 應用程序

    location /otherapp/ { try_files $uri @otherapp; }
            location @otherapp {
                include uwsgi_params;
                uwsgi_pass unix:/tmp/otherapp.sock;
            }

    location / { try_files $uri @baseapp; }
            location @baseapp{
                include uwsgi_params;
                uwsgi_pass unix:/tmp/baseapp.sock;
            }

您可以通過以下方式將頁面重定向到其他應用程序

@app.route('/')
def test():
    return redirect('/otherapp')

我希望我理解你的問題。 您希望有一條路線將您帶到 HTML 頁面,然后能夠單擊該頁面上的鏈接將您帶到另一條路線。

你可以這樣做:app.py 中的第一個 function

@app.route('/'):
def index():
   return render_template("index.html")

您的 index.html 文件可能如下所示:

<body>
<a href="/register">Register</a>
</body>

app.py中的第二個function:

@app.route('/register')
def register():
   # Ensure the user reached path via GET
   if request.method == "GET":
      return render_template("another_file.html")

   else:
      pass # Pass is a Python way to say 'do nothing'

我在第二個 function 中包含了一個條件語句,因為您可能希望用戶通過提交表單來注冊。 如果你這樣做,你可能想要根據請求方法做不同的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM