Python + Flask应用程序在127.0.0.1上由Pycharm运行后从错误的文件夹运行 [英] Python + Flask App runs from wrong folder after run by Pycharm on 127.0.0.1
问题描述
设置:
我已经在 OperationalError:(sqlite3.OperationalError)无法打开数据库文件 即错误的资料夹。整个项目,包括 非常感谢你的回答!他们带领我去找出什么事情和你们在哪里非常接近! I have created and populated a OperationalError: (sqlite3.OperationalError) unable to open database file
When i run C:\Program Files (x86)\JetBrains\PyCharm 4.0.6\jre\jre\bin. that is the wrong folder. The whole project, including the
Thank you both so much for your answers! They led me on the path to figuring out what was up and you where very close!
I had to change the 这篇关于Python + Flask应用程序在127.0.0.1上由Pycharm运行后从错误的文件夹运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Pycharm中创建并填充了一个
sqllite数据库
/ code>,运行 Python +
Flask +
SQLAlchemy
。
代码在控制台中完美运行,但是当我运行它时,我得到了一个:
lockquote
问题:
<在Chrome / Flask-Werkzeug中运行 print os.getcwd()
:
lockquote
C:\ Program Files(x86)\JetBrains\PyCharm 4.0.6\jre\jre\bin。
.db
在 C:\ Users \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
为什么是这样,我该怎么办呢?
代码:
$ p $ Base = declarative_base()
engine = create_engine(sqlite:///temp/database.db)
DBSession = sessionmaker(bind = engine)
session = DBSession()
** more进口,DB-Setup&类**
类DBHandl():
@classmethod
get getData(self):#返回Personen + Adressen
q = session.query(Person,Address) .filter(Person.id == Address.person_id).all()
return q
@ app.route('/')
def hello_world():
q = DBHandl.getData()
return render_template(home.html,list = q)
我必须改变运行/调试配置
,当你点击我的项目
右上角和编辑配置
。
那里我改变了工作目录Setup:
sqllite database
in Pycharm
, running Python
+ Flask
+ SQLAlchemy
.
The code works perfectly in the console, but when i run it, i get a:
Problem:
print os.getcwd()
in Chrome/Flask-Werkzeug:
.db
is in C:\Users\Finn\PycharmProjects
.
Why is that and what do i do about it? Code:
Base = declarative_base()
engine = create_engine("sqlite:///temp/database.db")
DBSession = sessionmaker(bind=engine)
session = DBSession()
**more Imports, DB-Setup & Classes**
class DBHandl():
@classmethod
def getData(self): # Return Personen + Adressen
q = session.query(Person, Address).filter(Person.id == Address.person_id).all()
return q
@app.route('/')
def hello_world():
q = DBHandl.getData()
return render_template("home.html", list=q)
Run/Debug Configurations
that open up when you click on my Project
in the upper right corner and edit configurations
.
there i changed the working directory