Failing at Importing Flask into Pre-existing Repl

Question: I’m trying to use Flask in my pre-existing Replit file (as per a friend’s recommendation) in hopes of building a database that pulls up an animal that the user enters and I don’t think I did it properly. I’m not sure what happened, but after I copied and pasted my code and sorted the HTML, CSS, and JavaScript files into ‘static’ and ‘templates’, I keep getting a ‘Replit not Found error’, even when I move the index.html file out of the folder. Any help please?:face_holding_back_tears:

Repl link: [REDACTED]

Here’s the python code just in case too, as everything was working fine before.

from flask import Flask, render_template, request

app = Flask(__name__)

# Dummy data for demonstration
aquatic_animals = [
    {'ScientificClass': 'Scyphozoa', 'Phylum': 'Cnidaria'},
    {'ScientificClass': 'Anthozoa', 'Phylum': 'Cnidaria'},
    {'ScientificClass': 'Mammalia', 'Phylum': 'Chordata'},
    {'ScientificClass': 'Actinopterygii', 'Phylum': 'Chordata'}
]

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

@app.route('/check_animal', methods=['POST'])
def check_animal():
    # Retrieve user input
    animal = request.form['animal']

    # Check if the input matches any aquatic animal
    for a_animal in aquatic_animals:
        if animal.lower() == a_animal['ScientificClass'].lower() or animal.lower() == a_animal['Phylum'].lower():
            return f"Yes, {animal} is an aquatic animal."

    return f"No, {animal} is not found in our database of aquatic animals."

if __name__ == '__main__':
    app.run(debug=True)

what is the error? Try running this in the shell: pip install Flask
Alternativly, you can add this to the top of your code to install flask:

import os # the os module is always built-in. 
os.system("pip install Flask") # Run a system command

The problem is that this will keep trying to install everytime your run a program, even if it is installed, then it will say that it’s already installed, clogging up the Console.

3 Likes

I mean put that at the beginning 1 time, and then remove it from then on.

1 Like