Hot answers tagged

7

This command pip3 install --user -r requirements.txt --upgrade solves the problem according to this post on reddit (and the comments here :).


6

Give your select a name, and your options a value each. <select class="form-control" id="rating" name="rating"> <option value="5">5</option> <option value="4">4</option> <option value="3" selected>3</option> <option value="2">2</option> <option value="1">1</option> </...


6

They are warnings from pylint. You can tell pylint to ignore that error by create file .pylintrc in your folder with contains: ignored-classes=SQLObject,Registrant,scoped_session reference link: https://stackoverflow.com/questions/42789666/pylint-error-message-on-cloud-9-cs50


5

This can be easily solved by noting which terminal the export command was executed in the same terminal window that flask is running in (will be prompted to run in after the export command). Otherwise, flask cannot recognize the API_KEY as an environment variable, hardly being an environment variable.


4

So it seems the workaround solution was to add app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False somewhere after the app = Flask(__name__) The issue has been reported (https://github.com/pallets/flask/issues/2549, and duplicate https://github.com/pallets/flask/issues/2599), and is fixed in current release, so let's hope we get an updated version soon (as ...


4

Since "stocks" are in one list and "currentprices" are in another list you will get this result when you use two lists and two loops. One solution would be to use one loop and use currentprices[i] where i is indexed to the row in the "stocks" list. Another option would be to add a "price" key to each "stocks" row in the index() function instead of building ...


4

Inside the function for the respective routes you can just call the function "flash(message)" before the "return redirect()" function, where "message" is the message you want to display. for example: flash ("Bought") return redirect(url_for("index"))


3

The for loop is working and is displaying exactly the data it has. And it technically (theoretically?) is identical to a for loop in C. Perform this code x times. Syntactically, you (normally) tell C how many times (eg for (i = 0; i < strlen(somestring); i++). The for stock in stocks notation is "syntactic sugar"; it knows how long stocks is, so it does ...


3

Try to delete the following code in line 17. Session(app) At least it works for me in Mac.


2

How about if you create a new session key, like session['action'] = 'Bought' that gets set in the appropriate route?


2

The "something like" syntax in this call for the href attribute was wrong and has been corrected. It is more something like href="{{ url_for('buy', symbol=stock.symbol ) }}". stock.symbol should not be quoted nor escaped with braces. (the quotes make it a literal; the braces are only used to escape the objects from html). An a element ...


2

From the FAQs in the spec: OSError: [Errno 98] Address already in use If, upon running flask, you see this error, odds are you (still) have flask running in another tab. Be sure to kill that other process, as with ctrl-c, before starting flask again. If you haven’t any such other tab, execute fuser -k 8080/tcp to kill any processes that are (still) ...


2

https://en.m.wikipedia.org/wiki/Web_server A web server is server software, or hardware dedicated to running said software, that can satisfy World Wide Web client requests. A web server can, in general, contain one or more websites. A web server processes incoming network requests over HTTP and several other related protocols. As David Malan says that web ...


2

Have you tried export FLASK_DEBUG=ON


2

Try setting the first conditional in your index function to: if session.get("notes") is None: This way you will only reset the session's collection of notes when it actually did not yet exist. At the moment you posted your code, you probably had set: session["notes"] = "value" earlier on, this resulted in the first conditional always evaluating to 'True'...


2

jinja handles conditionals. One possible solution: Add a conditional in the <footer> block and send an indicator when the profile page is rendered. Sample html code: <footer> {% if not f1 %} <p> default footer </p> {% else %} <p> alternate footer </p> {% endif %} </footer> Add the ...


1

Your matrix needs to have len(a) + 1 rows of len(b) + 1 cells. The final distance is found in matrix[len(a)][len(b)], which does not exist in your current matrix. A cell matrix[row][col] corresponds to the transformation from a[0:row] into b[0:col], upper left cell matrix[0][0] would be empty string "" to "", lower right cell matrix[len(a)][len(b)] would ...


1

I'm not certain, but I'd venture to guess that it's for development purposes. You don't want caching to happen because your latest changes may not be reflected on the page; and as for storing the session locally, it is likely because you're testing multiple users and cookies might not behave as expected, you'd possibly have to deal with multiple cookies ...


1

You are missing the ) for your db.execute statement. Count the opening and closing parentheses.


1

if request.form.get("username") != True or request.form.get("password") != True or request.form.get("password") != request.form.get("confirmation"): request.form.get("username") and request.form.get("password") are strings. Instead of != True, use like if not request.form.get("username") or not request.form.get("password") or .... An empty string or even ...


1

I do not think the problem is in register function or register.html. I ran them through check50 and they passed. A little detail I missed on the initial read was "got 200 in all my apology pages", all being the operative. I can merely speculate, but it is possible that the older (2017) version of the application is in play. I believe you are using the 2017 ...


1

Search your flask script for --with-threads According to flask quickstart when running flask run your app will execute the FLASK_APP script so it appears you'll need to check that—whatever your app's script is—for --with-threads. From what I know and can tell it seems like whatever script start at flask run is trying to execute a program with the argument -...


1

Change the call from flask run to flask run --host=0.0.0.0 --port=8080 and it should work, as per this reddit post.


1

mkdtemp creates a directory in your temporary directory (most likely /tmp), there you'll find the files after login. They aren't removed on closing the server. The code uses URL http://download.finance.yahoo.com/d/quotes.csv?f=snl1&s=NFLX where I see "NFLX","Netflix, Inc.",194.7899


1

url_for accepts additional arguments that are used as GET parameters (look at the URL it redirects you to if you're not logged in). Your login template might pass those, and after successful login you can redirect the user to that parameter's content if this parameter is present. I implemented this recently in my version of finance, that's why I know ;)


1

Those are HTTP-Headers. The app uses them to tell the HTTP client (your browser) not to cache the response (otherwise the browser might try to reuse a response instead of doing the same request again). This is especially useful in dev environments (hence the test for "DEBUG" config), where you want a changed content to be applied instantly. If the browser ...


1

There is nothing in the posted code that would prevent the db.execute from executing more than one time. One possible explanation is the primary key or a unique index on the tables is preventing duplicates. For example if id is the primary key on histories, it will only allow one row per user id.


1

From the flask doc (The Request Object): What happens if the key does not exist in the form attribute? In that case a special KeyError is raised. You can catch it like a standard KeyError but if you don’t do that, a HTTP 400 Bad Request error page is shown instead. So for many situations you don’t have to deal with that problem. buyq does not exist in ...


1

There is no "thing" called category. From the Flask flash documentation: {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} <ul class=flashes> {% for category, message in messages %} <li class="{{ category }}">{{ message }}</li> {% endfor %} </ul> {% endif %} {% endwith %} ...


1

This sql "SELECT symbol, price, name, SUM(shares) AS quanties FROM shares WHERE id=:id" always returns one row. Try it in sqlite3/phpliteadmin. You need a GROUP BY clause . Since you (presumably) want one row per symbol, you would add GROUP BY symbol after the where clause (try that in sqlite3/phpliteadmin to see the difference).


Only top voted, non community-wiki answers of a minimum length are eligible