from flaskblog import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)```
```python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from flaskblog.config import Config
db = SQLAlchemy()
bcrypt = Bcrypt()
login_manager = LoginManager()
login_manager.login_view = 'users.login'
login_manager.login_message_category = 'info'
mail = Mail()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
bcrypt.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
from flaskblog.users.routes import users
from flaskblog.posts.routes import posts
from flaskblog.main.routes import main
app.register_blueprint(users)
app.register_blueprint(posts)
app.register_blueprint(main)
return app```
#๐ someone help pls sqlalchemy RuntimeError
161 messages ยท Page 1 of 1 (latest)
@lethal oriole
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
These are the errors.
I wrote the code above, as well.
What do I need to do to fix this...?
Do I need to write something instead of the dots?
here?
I'm not sure where I need to put that...
@verbal gyro
Someone help...I really want to make this code work...
So...I tried putting app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
But...
Now it gave another error.
Can someone tell me what I need to do?
app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///tmp/test.db' I tried it with this, 3 /'s instead of 4, and...
it still doesn't work...
Hmmmm...
I'm trying some other stuff, but it still doesn't seem to work...
I'm searching it on youtube rn.
No proper result...
Now it gives this error...
I've tried so many diffferent things, and none of them work...
@verbal gyro can you help?
someone help pls
someone help pls sqlalchemy error
This is the last thing I'll do with Flask for now, so I'd REALLY appreciate help.
Everything has worked thus far, but the LAST thing doesn't work...
๐
I just need one person to help, man...
someone help pls sqlalchemy RuntimeError
Hello
Hey @lethal oriole
Yesterday I saw your post was closed by you so I assumed you found a sol
does tmp dir and test.db exist?
from app import app
from app.models import (Applications, ApplicationStatus, Courses, Deans,
Professors, Students, db)
print("Database URI:", app.config["SQLALCHEMY_DATABASE_URI"])
with app.app_context():
db.create_all()
print("Database created")
Write a script like this and run it. This will create the db first
fix the import according to your application
you will need to do it where you create the app object
Nah
Nobody answered so
I had to close it.
I'll open my pc one sec.
I don't think there is tmp dir
hmmmmmm.
Let me send the imports.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from flaskblog.config import Config```
These?
where do I write this?
Command prompt or?
I think I need to type this in python?
"from app" gives a red underline...?
Hmmmm...
Yeah
No matter
where I put the app
it gives a red underline.
@unborn abyss
It says no module named app in the command prompt.
and in python it's red.
I do remember src being somewhere, yeah.
beautiful, I was about to ask for the dir structure haha
yeah
from flaskblog import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)```
yes.
can you share me the code in it?
Which code?
This is the run.py
can you share the code where the app obj is created?
ig it should be somewhere in main dir
hmmmm
or init file, im not sure
no worries you have shared it here, dint see
yeah main init is empty.
ah okay.
have you pushed all the code to a repo?
sqlite:///instance/data.db try this as the uri value
hmmm.
in config, right?
or wait
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')```
Do I write that here, then?
since flaskblog init doesn't have it
yes
instead of the database_url?
however later you will need to fetch the value from env vars
it's red...
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = sqlite:///instance/data.db
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')```
oh wait
I added '
as a string dude
yes yes
I realized that lol.
Hmmmm, I ran it...but will it work...?
...it didn't.
This same error again...
I ran into this error...what do I do now?
4 /'s?
I tried that before, but it didn't work.
try it now
which file contains this function: create_app
Maybe we can ask someone else for help, if you know someone?
I wonder if it's just as you said, it's just old...?
The code did work in the video, but that was in 2018...
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from flaskblog.config import Config
db = SQLAlchemy()
bcrypt = Bcrypt()
login_manager = LoginManager()
login_manager.login_view = 'users.login'
login_manager.login_message_category = 'info'
mail = Mail()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
bcrypt.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
from flaskblog.users.routes import users
from flaskblog.posts.routes import posts
from flaskblog.main.routes import main
app.register_blueprint(users)
app.register_blueprint(posts)
app.register_blueprint(main)
return app```
This also has the create_app.
@unborn abyss
it's in the flaskblog_init_.py.
I guess I will never know the answer to this error... ๐
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.