Flask action is not redirecting to the specified html page

I am using flask in pycharm to create a simple website. I am working on features that allow the user to register an account for the website and login using their created credentials. My problem currently is that the registration form isn’t consistently redirecting to the login page. It is only refreshing the page after providing a username and suitable password.

Heres what i’ve currently tried.

Registration HTML Form:

<form method="POST" action="{{url_for('register')}}">
        <!-- Defines username Fields -->
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required><br><br>
        <!-- Defines password Fields -->
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required><br><br>
        <!-- Defines Register Button -->
        <button type="submit">Register</button>
    </form>
Login HTML Form:

<form method="POST" action="{{url_for('login')}}">
        <!-- Defines username Fields -->
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required><br><br>
        <!-- Defines password Fields -->
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required><br><br>
        <!-- Defines Login Button -->
        <button type="submit">Login</button>
    </form>
Web Page Routes for both login and registration blocks:
from datetime import date
import re
from flask import Flask, render_template,  request, redirect, url_for, session

# Calls the imported flask function and sets to render the web pages in the "template" form
app = Flask(__name__, template_folder='template')
app.secret_key = 'your_secret_key'

#User Data and variables being used
users = [{'username': 'password'}]
#Password Complexity
PASSWORD_REGEX = r'^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[@$!%*?&])[A-Za-zd@$!%*?&]{12,}$'

# Defining the website routes
@app.route('/')
# Sets up registration page for the site
@app.route('/register', methods=['GET', 'POST'])
def register():
    '''Function that renders the registration page'''
    if request.method == 'POST':
        # Establishes the username and password variables to be inputted into the form
        username = request.form['username']
        password = request.form['password']
        if username in users:
            # Refreshes the page and prints a message when username already exists.
            return render_template('register.html', message='Username already exists.')
        if not re.match(PASSWORD_REGEX, password):
            # Refreshes the page and prints a message when password isn't complex enough
            return render_template('register.html', message='Password complexity not met.')

        users[username] = password
        # Redirects to the login screen
        return redirect(url_for('login'))

    return render_template('register.html',date=date.today())

# Sets up login page for the site
@app.route('/login', methods=['GET', 'POST'])
def login():
    '''Function that renders the login page'''
    if request.method == 'POST':
        # Establishes the username and password variables to be inputted into the form
        username = request.form['username']
        password = request.form['password']

        if username in users and users[username] == password:
            session['username'] = username
            # Redirects to the home page screen
            return redirect(url_for('home_page'))
        # Refreshes the page and prints a message when username already exists.
        return render_template('login.html', message='Invalid credentials.')
    #Renders the login page
    return render_template('login.html',date=date.today())

New contributor

robert crawford is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật