The basic problem is that I can run the hello world app but can't make other routes work.
I followed a tutorial. Project structure is as below:
testapp
__init__.py
passenger_wsgi.py
app(folder)
--templates(folder)
--static(folder)
The codes are:
__init__.py:
import os
from flask import Flask, request, render_template, redirect, url_for
project_root = os.path.dirname(os.path.realpath('__file__'))
template_path = os.path.join(project_root, 'app/templates')
static_path = os.path.join(project_root, 'app/static')
app = Flask(__name__, template_folder=template_path, static_folder=static_path)
@app.route('/')
def index():
return 'Hello, World'
passenger_wsgi.py:
import os
import sys
import importlib.util
sys.path.insert(0, os.path.dirname(os.path.realpath('__file__')))
spec = importlib.util.spec_from_file_location("wsgi", "__init__.py")
wsgi = importlib.util.module_from_spec(spec)
spec.loader.exec_module(wsgi)
application = wsgi.app
I followed the tutorial and everything went well. Then I tried to dig deeper.
(1)
I tried to add
@app.route('/login')
def login():
return 'login page.'
when I tried to access mydomain.com.au/testapp/login, it returned 404 error.
(2)
I tried to add index.html and login.html under templates folder. Make the structure like below:
testapp
myapp.py
passenger_wsgi.py
app(folder)
__init__.py
route.py
--templates(folder)
index.html
login.html
--static(folder)
I moved the code from myapp.py to app/__init__.py and app/route.py. It returned 404 error when tried to launch login page.
I am kinda lost. Passenger official also didn't mention any real samples and I can't find any anywhere. Can you please shine some light on it? Thanks so much.
Best Regards
Clement Ye
I followed a tutorial. Project structure is as below:
testapp
__init__.py
passenger_wsgi.py
app(folder)
--templates(folder)
--static(folder)
The codes are:
__init__.py:
import os
from flask import Flask, request, render_template, redirect, url_for
project_root = os.path.dirname(os.path.realpath('__file__'))
template_path = os.path.join(project_root, 'app/templates')
static_path = os.path.join(project_root, 'app/static')
app = Flask(__name__, template_folder=template_path, static_folder=static_path)
@app.route('/')
def index():
return 'Hello, World'
passenger_wsgi.py:
import os
import sys
import importlib.util
sys.path.insert(0, os.path.dirname(os.path.realpath('__file__')))
spec = importlib.util.spec_from_file_location("wsgi", "__init__.py")
wsgi = importlib.util.module_from_spec(spec)
spec.loader.exec_module(wsgi)
application = wsgi.app
I followed the tutorial and everything went well. Then I tried to dig deeper.
(1)
I tried to add
@app.route('/login')
def login():
return 'login page.'
when I tried to access mydomain.com.au/testapp/login, it returned 404 error.
(2)
I tried to add index.html and login.html under templates folder. Make the structure like below:
testapp
myapp.py
passenger_wsgi.py
app(folder)
__init__.py
route.py
--templates(folder)
index.html
login.html
--static(folder)
I moved the code from myapp.py to app/__init__.py and app/route.py. It returned 404 error when tried to launch login page.
I am kinda lost. Passenger official also didn't mention any real samples and I can't find any anywhere. Can you please shine some light on it? Thanks so much.
Best Regards
Clement Ye