我有一个从MSSQL数据库中获取表格并在ArcGIS中注册的脚本,同时使用了其他几种arcpy方法。我试图将其与Flask组合,并开发出一个HTML界面,您可以在其中指定表格。该脚本在控制台上运行得非常好,但是当在http://127.0.0.1:5000/上使用Flask运行时,arcpy函数不会运行,然后应用程序会抛出错误。
我正在使用我的本地python目录,因此在flask上导入arcpy没有任何问题。所以,我能够使用pymssql函数创建新表格,但是当涉及到arcpy函数时,它会抛出不存在的错误,尽管表格存在。我觉得在Flask中运行arcpy出了问题,但是任何帮助都将不胜感激。
(2) 我在Django中尝试了同样的事情,但遇到了同样的问题。
谢谢
forms.py
class createGISLayer(FlaskForm):
tCreateLayer = SubmitField('Create GIS Layer')
仪表板主函数()
try:
cursor.execute(QueryCreate)
print ("Table Created.")
print(self.dbTablePath)
descTable = arcpy.Describe(self.dbTablePath)
except arcpy.ExecuteError:
print(arcpy.GetMessages())
app.py
if formCreate.tCreateLayer.data and formCreate.validate_on_submit():
if myLayer is not None:
try:
print("Create GIS Layer")
myLayer.dashboardMain()
flash('GIS Layer created!', 'success')
except Exception as e:
print(e.message)
flash(e.message, 'danger')
首页文件
<!-- Create GIS Layer -->
<div class="content-section">
<form name='idCreateGISLayer' action="" method="POST">
<table style="height: auto; margin-left: auto; margin-right: auto; width: 600px;">
<tbody>
<tr>
{{ formCreate.hidden_tag() }}
<td style="height: 39px; width: 259px">
<h2 style="text-align: left;"><font size="3"><strong>(2) Create </strong></font></h2>
</td>
<td style="text-align: left; height: 39px;">
<div class="auto-style2">
{{ formCreate.tCreateLayer(class="btn btn-outline-info")}}
</div>
</td>
</tr>
</tbody>
</table>
</form>
</div>
错误
Table Created.
F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1
"F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1" does not exist
from pathlib import Path dbTablePath = ... # 列出目录中的所有文件 p = Path(dbTablePath) for f in p.iterdir(): print(f) # 或者 for f in p.parent.iterdir(): print(f)
- Leon Klute