2

trying to follow a tutorial and unsure where I am going wrong. I have tried walking through this multiple times and I'm really drawing a blank. Hopefully someone can point a beginner in the correct direction.

from flask import Flask,render_template,url_for,flash,redirect
from flask_sqlalchemy import SQLAlchemy
import os
basedor = os.path.abspath(os.path.dirname(__file__))

class Config(object):
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATEBASE_URL') or 'sqlite:///' + os.path.join(basedir, 'app.db')
    SQLALCHEMY_TRACK_MODIFICATION = False
    POST_PER_PAGE = 3

app = Flask(__name__)
app.config['SECRET_KEY'] = SECRET_KEY
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
db=SQLAlchemy(app)

class User(db.Model):
    id=db.Column(db.Integer, primary_key=True)
    username=db.Column(db.String(120), nullable=False)
    password=db.Column(db.String(60), nullable=False)

    def __repr__(self):
     return f"User('{self.username}')"

The error I am getting is below, I know this is because of the location. Some guidance would be superb.

File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 466, in create_connect_args raise exc.ArgumentError( sqlalchemy.exc.ArgumentError: Invalid SQLite URL: sqlite://app.db

r mc
  • 21
  • 1
  • 1
    It looks like `os.environ.get('DATEBASE_URL')` is returning a value that is missing a slash: `sqlite://app.db` instead of `sqlite:///app.db` – Gord Thompson Dec 08 '20 at 12:53
  • 1
    That doesn't look much like a Windows path. You’ve also misspelled basedir vs basedor. Be sure to follow Windows path conventions instead when reading Linux/macos tutorials. – JL Peyret Dec 08 '20 at 15:50
  • See if can get some ideas from https://www.connectionstrings.com/sqlite/ or https://stackoverflow.com/a/56417062/1394353 – JL Peyret Dec 08 '20 at 15:54
  • Also http://docs.sqlalchemy.org/en/latest/core/engines.html. They have Windows examples for sqllite. Try hardcoding it first. – JL Peyret Dec 08 '20 at 16:06

0 Answers0