Skip to content Skip to sidebar Skip to footer

Routing Pages Using Flask And Deploying On Cpanel

Hy I'm new to flask and trying to get my first site up, I have been trying this for a couple of days now with little to no progress, Here is some code: from flask import Flask, ren

Solution 1:

Firstly, you need to change the redirect(url_for('proceed')) to redirect(url_for('confirm'))

And the code should look like this:

from flask import Flask, render_template, url_for, redirect, request, session

app = Flask(__name__)

@app.route('/', methods=["POST", "GET"])defpurchase():
    try:
        
        if request.method == "POST":
            email = request.form["email"]
            # Query the data base to find the exact amount and name of buyer

            session["user"] = email
            return redirect(url_for("cofirm"))
            
        else:
            return render_template("index.html",logged_in=True)
            
    except Exception as e:
        return(str(e))


@app.route("/confirm")defproceed():
    # Get information and create another formif"user"in session:
        returnf"""<h1>{session["user"]}</h1>"""else:
        returnf"""<h1>No email found</h1>"""if __name__ == "__main__":
    
    app.run()

And since you are hosting on Cpanel, change your .htaccess file to add the following so apache redirect all the not-found URL to your application

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]

Solution 2:

Add the following rules to your .htaccess in the directory of your application URL

RewriteEngine on
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

Post a Comment for "Routing Pages Using Flask And Deploying On Cpanel"