jakerieger / flaskintroduction Goto Github PK
View Code? Open in Web Editor NEWRepo for my tutorial on freeCodeCamp.org
Repo for my tutorial on freeCodeCamp.org
hey Jake running through the code and getting'Todo' has no attribute 'date_created' this could be me but I cannot figure it out for the life of me.
macOS Venture 13.4
Python 3.11.3
>>> from app import db
>>> db.create_all()
returns
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'db' is not defined
>>>
KeyboardInterrupt
>>> from app import db
>>> db.create_all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/fthobe/dev/tagverified/env/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 884, in create_all
self._call_for_binds(bind_key, "create_all")
File "/Users/fthobe/dev/tagverified/env/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 855, in _call_for_binds
engine = self.engines[key]
^^^^^^^^^^^^
File "/Users/fthobe/dev/tagverified/env/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 636, in engines
app = current_app._get_current_object() # type: ignore[attr-defined]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/fthobe/dev/tagverified/env/lib/python3.11/site-packages/werkzeug/local.py", line 508, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
when trying to create db from following code:
#Load the applications you need to run for your first webserver, render templates and link to static files
from flask import Flask, render_template, url_for
#Load the SQL Connector
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
#Create an app that hosts the service
app = Flask(__name__)
#Specify where the local SQLITE DB is located
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
#Specify what initialises the DB point to your app.py
db = SQLAlchemy(app)
#Start defining the DB and the columns
#Define a progressively numbered integer given by the DB for every item in the list
#A primary key is a column or group of columns used to identify the uniqueness of rows in a table. Each table has one and only one primary key.
#A db.string contains the task and can be maximum 200 characters long, nullable indicates that it can not be empty.
#Adds a boolean for every task created
#SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).
#SQLite recognizes the keywords "TRUE" and "FALSE", as of version 3.23.0 (2018-04-02) but those keywords are really just alternative spellings for the integer literals 1 and 0 respectively.
class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(200), nullable=False)
completed = db.Column(db.Integer, default=0)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<Task %r>' % self.id
with app.app_context():
db.create_all()
#"app.route" tell your server to which url it should respond. "/" means your base folder such as example.com/
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
#app.run starts the app and contains variables and configures the app to run on localhost ("host=0.0.0.0"), the port (you can use a different one than 80) and sets it in debug mode ("debug=True")
app.run(host='0.0.0.0', port=80, debug=True)
any idea?
Thanks for checking out my Flask tutorial repo! Since this is a tutorial repository, it's not updated unless a major breaking issue is discovered.
Because of the reason mentioned, please follow the checklist below when opening an issue.
Make sure to add all the information needed to understand the problem so that I can help. If the info is missing I'll add the 'Needs more information' label and close the issue until there is enough information.
Heroku error logs
app[web.1]: from collections import Mapping
app[web.1]: ImportError: cannot import name 'Mapping' from 'collections' (/app/.heroku/python/lib/python3.10/collections/__init__.py)
app[web.1]: [2022-06-06 01:04:01 +0000] [9] [INFO] Worker exiting (pid: 9)
heroku[web.1]: State changed from starting to up
app[web.1]: [2022-06-06 01:04:01 +0000] [4] [INFO] Shutting down: Master
app[web.1]: [2022-06-06 01:04:01 +0000] [4] [INFO] Reason: Worker failed to boot.
heroku[web.1]: Process exited with status 3
heroku[web.1]: State changed from up to crashed
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=xxx1stflasktodoapp.herokuapp.com request_id=a7537c8d-1ea1-4ab0-9e05-184b2ea55c36 fwd="160.97.243.190" dyno= connect= service= status=503 bytes= protocol=https
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=xxx1stflasktodoapp.herokuapp.com request_id=df90230f-ab93-4718-849d-58a7c81993c2 fwd="160.97.243.190" dyno= connect= service= status=503 bytes= protocol=https
Every time I press "Add Task", it takes me to the "there was an issue adding your task" page, however, after returning back to the homepage, I can see that the task was successfully inserted. what is our mistake :(
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.