这是将 sqlalchemy 会话连接到数据库文件的代码
from sqlalchemy.orm import sessionmaker
from DB_setup_alchemy import Base,User,Visitor,VisitRecord
from os import getcwd
# link to the DB we are using
# pay attention to this part, if without check_same_thread=false, there will be lots of errors
# but what is going on behind this part of code
# what does engine and session really means
db_path='sqlite:///'+getcwd()+'/data.db'
print(db_path)
engine = create_engine(db_path,connect_args={'check_same_thread': False})
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
我项目的所有文件都在 flaskapp 文件夹中
drwxrwxr-x 9 ubuntu ubuntu 4096 Apr 11 20:09 .
drwxr-xr-x 3 root root 4096 Apr 11 04:11 ..
drwxrwxr-x 2 ubuntu ubuntu 4096 Apr 11 04:31 .aws
drwxrwxr-x 5 ubuntu ubuntu 4096 Apr 11 20:38 flaskapp
drwx------ 2 root ubuntu 4096 Apr 11 20:11 test
flaskapp 文件夹中的文件:
drwxrwxr-x 5 ubuntu ubuntu 4096 Apr 11 20:38 .
drwxrwxr-x 9 ubuntu ubuntu 4096 Apr 11 20:09 ..
-rw-rw-r-- 1 ubuntu ubuntu 345 Apr 11 16:37 AWS_API.py
drwxrwxr-x 2 ubuntu ubuntu 4096 Apr 11 17:37 __pycache__
-rw-rw-r-- 1 ubuntu ubuntu 296 Apr 11 16:23 app.wsgi
-rwxrwxr-x 1 ubuntu ubuntu 20480 Apr 11 17:37 data.db
-rw-rw-r-- 1 ubuntu ubuntu 7426 Apr 11 20:38 flaskapp.py
-rw-rw-r-- 1 ubuntu ubuntu 6 Apr 11 04:34 index.html
drwxrwxr-x 2 ubuntu ubuntu 4096 Apr 11 16:46 templates
drwxrwxr-x 4 ubuntu ubuntu 4096 Apr 11 16:13 venv
data.db 和文件夹flask 都对ubuntu 组中的用户具有权限,我可以看到用户www-data 也在ubuntu 组中:
(venv) ubuntu@ip-172-31-24-93:~/flaskapp$ groups ubuntu
ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip www-data video plugdev lxd netdev
但如果我输入:groups www-data
(venv) ubuntu@ip-172-31-24-93:~/flaskapp$ groups www-data
www-data : www-data
这是来自浏览器的错误:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
我尝试了简单的打印你好网络应用程序,它正在工作。所以,我想知道我应该怎么做才能更改所有者或文件权限以使我的烧瓶应用程序正常工作?
富国沪深
阿波罗的战车
相关分类