Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from flask import Flask, render_template, url_for, flash, redirect from forms import RegistrationForm, LoginForm from werkzeug.security import generate_password_hash, check_password_hash import shelve app = Flask(__name__, template_folder='template') app.app_context().push()

from flask import Flask, render_template, url_for, flash, redirect from forms import RegistrationForm, LoginForm from werkzeug.security import generate_password_hash, check_password_hash import shelve app = Flask(__name__, template_folder='template') app.app_context().push() app.config['SECRET_KEY'] = 'HELLO WORLD!' db = shelve.open("site.db", writeback=True) class User(object): def __init__(self, username, email, password): self.username = username self.email = email self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) @app.route("/") def index(): return redirect(url_for('login')) @app.route("/register", methods=['GET', 'POST']) def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, password=generate_password_hash(form.password.data)) if form.email.data in db: flash('Email already exists.', 'danger') return redirect(url_for('register')) db[form.email.data] = user flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form) @app.route("/login", methods=['GET', 'POST']) def login(): form = LoginForm() if form.validate_on_submit(): if form.email.data in db: user = db[form.email.data] if check_password_hash(user.password, form.password.data): flash('You have been logged in!', 'success') return redirect(url_for('home')) flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form) if __name__ == '__main__': app.run(debug=True) db.close() 

this is my python so basically i want to do register a user by using registration form and using that created to login if the login is sucessful it will redirect to the home page now my problem is when i tried to login using using the correct credientials it still stuck in login and does not enter to the home and when i tried manually /home in the web page it shows (

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.) i have already specified the home page accordingly because when i tried /login and /register it works only /home having the issue could you help troubleshoot the problem and give the solution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago