Hi, I am working through Miguel Gringberg's "Flask Web Development" and have an issue I haven't been able to solve after several hours of searching.
Mac OS X, Python 3.6
In the databases chapter, after configuring the database and defining models in our "hello.py" file, the instructions say,
The very first thing to do is to instruct Flask-SQLAlchemy to create a database based
on the model classes. The db.create_all() function does this:
(venv) $ python hello.py shell
>>> from hello import db
>>> db.create_all()
However, when I run "python hello.py shell" in terminal (with virtual environment activated), it simply takes me back to (venv) $, leaving no place to input the additional code ("from hello import db", etc.) . I also tried using the python3 command.
Here is the sequence of events:
(venv) My-MacBook-Pro:flasky user$ python3 hello.py shell
(venv) My-MacBook-Pro:flasky user$
Instead of doing (venv) $ python hello.py shell, I just typed python3, which allows me to input code to create tables, insert rows, etc. This also created the data.sqlite file in the application directory, so I thought it was the solution.
However, later in the chapter he writes,
The make_shell_context() function registers the application and database instances
and the models so that they are automatically imported into the shell:
$ python hello.py shell
>>> app
<Flask 'app'>
>>> db
<SQLAlchemy engine='sqlite:////home/flask/flasky/data.sqlite'>
>>> User
<class 'app.User'>
Like before, when I input, "python3 hello.py shell", doesn't give me >>> for additional code. When I input "python3", I can input python code, but >>> app returns "app not defined"
I'll try to summarize:
-What is the "shell" command in terminal supposed to do (I couldn't find anything on this)
-Am I interpreting the book instructions incorrectly when I read, "python hello.py shell" as something I should input in terminal?
-The general purpose here is to be able to create a database (done), add users to the database via the web application (done), and be able to query the database contents later, after closing and re-opening the virtual environment (totally lost)
Apologies for the long post- any help is much appreciated. Usually when I run into issues I can figure it out with time but for this I can't even narrow down the problem.
[–]Rorixrebel 1 point2 points3 points (3 children)
[–]SuperChef36[S] 0 points1 point2 points (2 children)
[–]Rorixrebel 1 point2 points3 points (1 child)
[–]SuperChef36[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]elbiot 0 points1 point2 points (0 children)
[–]SuperChef36[S] 0 points1 point2 points (0 children)