Giter Site home page Giter Site logo

flaskintroduction's Introduction

GitHub Streak

Howdy ๐Ÿ‘‹

Just a dude that likes to make computers do things. Memory and low level code gets me hot and bothered. Aspiring graphics programmer. I'm in an abusive relationship with C++, please help.

  • ๐ŸŽ“ Instructor at freeCodeCamp
  • ๐Ÿซ Cybersec Engineering major

flaskintroduction's People

Contributors

jakerieger avatar kohlchelsea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flaskintroduction's Issues

RuntimeError: Working outside of application context. when creating SQLite DB

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?

Attribute missing in the example

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.

Encountered an application error when deployed on Heroku using python 3.10.4

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.