flask
I connected the profile function to the main application, registered blueprints in it, added it to the main application. I added debug outputs to check if the function is running, but they didn’t output anything
Here’s my code
views.py
...
views_bp = Blueprint('views', __name__)
@views_bp.route('/profile')
@login_required
def profile():
print("In profile route")
print(f"Session: {session}")
#debug
if current_user.is_authenticated:
print(f"Current user: {current_user.id}")
else:
print("No user authenticated.")
...
create_app.py
...
from views import views_bp
from models import User, db
login_manager = LoginManager()
def create_app():
pymysql.install_as_MySQLdb
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
app.config['SQLALCHEMY_DATABASE_URI'] = '<db.url>'
app.config['SECRET_KEY'] = '<my secret code>'
db.init_app(app)
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
app.register_blueprint(auth_blueprint)
app.register_blueprint(views_bp, url_prefix='/auth')
return app
...
I tried adding the following code to the same file:
...
@views_bp.route('/test')
def test():
return "Test Page"
...
and it worked, i saw “Test page” on http://127.0.0.1:5000/auth/test
also i tried to remove @login_required to see, if it’s the problem, but no.
I don’t know, most likely some very stupid mistake, but I haven’t been able to find it for a long time
if I need to add something to the question – let me know
I discovered that in my other blueprint I had a function for /profile that I added for debugging and forgot to remove, I feel very stupid