Hot answers tagged

7 votes

Runtime Error: API_KEY not set

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,...
7 votes
Accepted

IndexError in initial state of pset6 Sentiments

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

How to get a value using flask, from a selected option in a drop down list?

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</...
  • 20.7k
6 votes

Instance of 'scoped_session' has no 'commit' member

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: ...
  • 61
4 votes
Accepted

jsonify not working when I add this line of code <<db = SQL("sqlite:///mashup.db")>> to application.py

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/...
  • 20.7k
4 votes
Accepted

cs50 finance / pset-7 confused on index() table

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] ...
4 votes
Accepted

Using jinja to render template based on previous url - pset7 finance

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: ...
3 votes
Accepted

Pset7, Index: How to use loops in Python and Jinja?

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 ...
3 votes

Web CS50 Project 1: 'flask.cli.NoAppException' flask app with sqlalchemy

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

Using jinja to render template based on previous url - pset7 finance

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

How to pre-populate sell() and buy() forms from index - Pset7

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....
2 votes
Accepted

"flask run" error in pset6 sentiments

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 ...
2 votes

What is a web server?

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 ...
  • 142
2 votes

How do I turn debug mode ON in flask?

Have you tried export FLASK_DEBUG=ON
  • 18.4k
2 votes
Accepted

Flask Sessions Not Working

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 ...
  • 136
2 votes
Accepted

Is there a way in jinja to display a block in a specific page?

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 ...
2 votes

Lab9 -- Buttons to delete DB entries don't work

One problem is the html sends person.id as a list ( value="{{ [person.id] }}) so it will never find a match in the db. Once that is fixed another problem will be discovered: it will not add ...
1 vote

Should my distances function return the matrix in PSET6?

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 ...
  • 20.7k
1 vote
Accepted

PSET 7 - Finance - application.py

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 ...
1 vote

Pset7 - Finance (register function) - creating internal server error

You are missing the ) for your db.execute statement. Count the opening and closing parentheses.
  • 20.7k
1 vote
Accepted

Check50 returning error pset7 register

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("...
  • 20.7k
1 vote
Accepted

expected 400 but got 200 OK?

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 ...
1 vote

Problem with flask

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 ...
1 vote
Accepted

Help needed for CS50 IDE flask server

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 vote
Accepted

Where is session file and where is company's name in csv file?

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....
  • 20.7k
1 vote
Accepted

What is next parameter in the url_for function?

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 ...
  • 20.7k
1 vote
Accepted

What is cache and how could you stop it?

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)....
  • 20.7k
1 vote

db.execute() executing only single time

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 ...
1 vote

Runtime Error: API_KEY not set

If anyone is still having a problem to set API_KEY as an environmental variable, remember to do it following this syntax (in VSCODE terminal or powershell for WINDOWS): $env:API_KEY="YOUR-API-KEY-...
1 vote

C$50 PSET7 Flask blank form question

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 ...

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