This is my init .py file. I am trying to hash user passwords in my other file using Bcrypt. Following code is init .py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
app = Flask(__name__)
app.config['SECRET_KEY'] = '5791628bb0b13ce0cfde280ba245'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///smashpass.db'
db = SQLAlchemy(app) # Database instance
bcrypt = Bcrypt(app)
# Beware of circular imports
from smashpass import routes
Then the snippet of the code invoking Bcrypt()
form = RegistrationForm()
if form.validate_on_submit():
hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
user = User(username=form.username.data, email=form.email.data, password=hashed_password)
db.session.add(user)
db.session.commit()
This is the error reviewed after:
Traceback (most recent call last):
File "run.py", line 1, in <module>
from smashpass import app
File "C:\Users\user\PycharmProjects\smashpass\smashpass\__init__.py", line 3, in <module>
from flask_bcrypt import Bcrypt
ModuleNotFoundError: No module named 'flask_bcrypt'
Thanks in advance.
You must first install the module:
pip install flask-bcrypt
Also according to the documentation , the import statement should look like this:
from flask.ext.bcrypt import Bcrypt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.