0

This is the error im getting using uwsgi on my webserver

*** Operational MODE: single process ***
ModuleNotFoundError: No module named 'app'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15225)
spawned uWSGI worker 1 (pid: 15230, cores: 1)

I used this tutorial to handle logins in flask. Which is different from any flask project i used since there is no file called app.py with the addition of

app = Flask(__name__)

if __name__ == "__main__":
    app.run()

inside of it, which confuses me and took me now a whole day to figure out how to deploy this, but im not able to get it done. Every guide to solve this used either docker or was built up with an app.py

I am also able to get this to run by using it locally using the command flask run in terminal. But unable to use uwsgi and adding it to a demon.

Hopefully someone is able to help. I am trying to start it on my server with uwsgi uwsgi.ini

my uwsgi.ini

[uwsgi]
module = app:app
pidfile = basic_flask_template.pid
master = true
processes = 1
http-socket = :1024
chmod-socket = 660
vacuum = true

my init.py

# init.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager 

# init SQLAlchemy so we can use it later in our models
db = SQLAlchemy()

app = create_app()
def create_app():

    app.config['SECRET_KEY'] = 'secretkey'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'

    db.init_app(app)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))

    # blueprint for auth routes in our app
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    # blueprint for non-auth parts of app
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app

my main.py

# main.py

from flask import Blueprint, render_template
from flask_login import login_required, current_user

main = Blueprint('main', __name__)

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

@main.route('/profile')
@login_required
def profile():
    return render_template('profile.html', name=current_user.name)

my models.py

# models.py

from flask_login import UserMixin
from . import db

class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
    email = db.Column(db.String(100), unique=True)
    password = db.Column(db.String(100))
    name = db.Column(db.String(1000))

and my auth.py

# auth.py

from flask import Blueprint, render_template, redirect, url_for, request, flash
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import login_user, logout_user, login_required
from .models import User
from . import db

auth = Blueprint('auth', __name__)

@auth.route('/login')
def login():
    return render_template('login.html')

@auth.route('/login', methods=['POST'])
def login_post():
    email = request.form.get('email')
    password = request.form.get('password')
    remember = True if request.form.get('remember') else False

    user = User.query.filter_by(email=email).first()

    # check if user actually exists
    # take the user supplied password, hash it, and compare it to the hashed password in database
    if not user or not check_password_hash(user.password, password): 
        flash('Please check your login details and try again.')
        return redirect(url_for('auth.login')) # if user doesn't exist or password is wrong, reload the page

    # if the above check passes, then we know the user has the right credentials
    login_user(user, remember=remember)
    return redirect(url_for('main.profile'))

@auth.route('/signup')
def signup():
    return render_template('signup.html')

@auth.route('/signup', methods=['POST'])
def signup_post():

    email = request.form.get('email')
    name = request.form.get('name')
    password = request.form.get('password')

    user = User.query.filter_by(email=email).first() # if this returns a user, then the email already exists in database

    if user: # if a user is found, we want to redirect back to signup page so user can try again  
        flash('Email address already exists')
        return redirect(url_for('auth.signup'))

    # create new user with the form data. Hash the password so plaintext version isn't saved.
    new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256'))

    # add the new user to the database
    db.session.add(new_user)
    db.session.commit()

    return redirect(url_for('auth.login'))

@auth.route('/logout')
@login_required
def logout():
    logout_user()
    return redirect(url_for('main.index'))
Yierith
  • 1
  • 2
  • You don't say which tutorial you follow. I do see that you assign `app` in `init.py`. Have you researched the error? For example, when searching for *unable to load app 0 mountpoint*, I found https://stackoverflow.com/questions/34210995/flask-uwsgi-throws-error-unable-to-load-app-0-mountpoint. There are many other documents that mention the same error message. – berndbausch Feb 11 '21 at 07:59
  • Sorry hyperlink was broken, its working now, yes i searched for a couple of hours for the error. But didn't find any solutions to using "auth = Blueprint('auth', __name__)" type of apps – Yierith Feb 11 '21 at 08:14
  • noone able to help? – Yierith Feb 13 '21 at 23:45

0 Answers0