0

I'm learning how to create web apps in Python using flask, and I want to add one to my WordPress website, but I'm stuck on the same problem for 2 days already. Somebody, please explain what am I doing wrong. After I installed the app using cPanel, I was able to access its index page in Google Chrome (although in Firefox it returns sometimes "Web application could not be started by the Phusion Passenger application server."), but all the other pages return 404 error. At first, html forms were trying to access pages starting from the root of the website, i.e. example.com/page, instead of example.com/app_folder/page, but I fixed it by writing <form action="{{ url_for('page') }}" method="post"> instead of <form action="/page" method="post">.

So the links are correct, but its still 404. The application.py code for the first 2 routes is like this:

app = Flask(__name__)

app.config["TEMPLATES_AUTO_RELOAD"] = True

app.config["DEBUG"] = True

# Configure CS50 Library to use SQLite database
db = SQL("sqlite:///companies.db")

@app.route("/")
def index():
    companies = db.execute("SELECT * FROM companies ORDER BY women DESC")
    return render_template("index.html", companies=companies)


@app.route("/company")
def company():
    company = request.args.get("company")
    return render_template("company.html", company=company)

HTML form in index.html which should send request to '/company':

<form id="company" action="{{ url_for('company') }}" method="get">
    <input type="hidden" name="company" value="{{company.company_name}}">
    <input type="submit" value="?">
</form>

And company.html is in the same "templates" folder as index.html.

I have installed and imported all the necessary libraries. And the app worked well when run independently on IDE. But now its '/company' and any other non-root routes return 404. I've tried messing up with passenger_wsgi.py, but the result seems the same whatever I write in it, even if it's empty or has the same code as application.py.

I've tried to explicitly tell it to look for HTML in templates folder (no effect). And I've tried adding empty folders with route names to the app directory as was recommended in one question, but then it just returns 404 or "Web application could not be started by the Phusion Passenger application server."

Adding if __name__ == '__main__': app.run() in the very end of application.py doesn't seem to do anything either.

I'm out of ideas. If somebody have experienced a similar problem before, please tell me how you solved it.

Dziyana
  • 31
  • 4

1 Answers1

0

I had the same problem and I found something closer to the solution here:

Python flask app routing in cpanel: can only access root url

After following these instructions, I don't get 404 error anymore, but now the different routes only take me back to root.

  • If the answer to a question is a link to another answer on Stack Overflow, please [flag](https://stackoverflow.com/help/privileges/flag-posts) the question as a duplicate rather than creating an answer. – snakecharmerb Aug 07 '21 at 14:49