Python Forum

Full Version: Error: While importing "app", an ImportError was raised:
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code works well in a IDE online, but in my VSCODE does not work, it has the next error. What is the error??
Note: In my VSCODE I works in flask with: python -m flask run
And all my codes with FLASK works fine but this does not work.

Traceback (most recent call last):
File "C:\Users\channel66\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\", line 240, in locate_app
File "E:\flaskapplic\tasks2\", line 2, in <module>
from flask_session import Session
ImportError: cannot import name 'Session' from 'flask_session' (unknown location)
from flask import Flask, render_template, redirect, request, session
from flask_session import Session

app = Flask(__name__)

app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"

def tasks():
    if "todos" not in session: 
        session["todos"] = [] 
    return render_template("tasks.html", todos = session["todos"])   

@app.route("/add", methods = ["GET", "POST"])
def add():
    if request.method == "GET":
        return render_template("add.html")
        todo = request.form.get("task")
        return redirect("/")
in folder templates


{% extends "layout.html" %}

{% block body %}
<form action="/add" method="post">
<input id="task" name="task" type="text" placeholder="Task Name">
<input id="submit" type="submit" disabled>
document.getElementById("task").onkeyup = function () {
if (document.getElementById("task").value =="")
document.querySelector("#submit").disabled = true;
else {
document.querySelector("#submit").disabled = false;
{% endblock%}


<!DOCTYPE html>
<html lang= "en">
<title>{% block title %}Tasks{% endblock %}</title>

{% block body %}
{% endblock %}


{% extends "layout.html" %}

{% block body %}
{% for todo in todos %}
<li>{{ todo }}</li>
{% endfor %}
<a href="/add">Create a New Task</a>
{% endblock %}
The solution was very simple
VSCODE terminal ...
pip install Flask-Session

SOLVED!!! CLOSE the thread.
Get into the habit of listing the third-party libraries that your project uses in a requirements.txt file. That way you don't need to worry about remembering what they all are and which versions you're using. See this section of the pip docs.