2 次代码提交

作者 SHA1 备注 提交日期
  Carlos Hernandez 8604219fd5 Find way to display articles content from API 3 年前
  Carlos Hernandez f3b526ab63 Find way to display articles content from API 3 年前
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 3
    0
      .gitignore
  2. 3
    3
      Files-API/files_api.py

+ 3
- 0
.gitignore 查看文件

@@ -1,3 +1,6 @@
1
+# Local
2
+.vscode
3
+
1 4
 # Byte-compiled / optimized / DLL files
2 5
 __pycache__/
3 6
 *.py[cod]

+ 3
- 3
Files-API/files_api.py 查看文件

@@ -1,5 +1,5 @@
1 1
 import os
2
-from flask import Flask, send_from_directory, jsonify
2
+from flask import Flask, send_from_directory, jsonify, current_app
3 3
 from flask_cors import CORS, cross_origin
4 4
 
5 5
 
@@ -20,8 +20,8 @@ def send_text_file(article):
20 20
 @cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
21 21
 def list_files():
22 22
     files = list()
23
-    for filename in os.listdir("articles"):
24
-        path = os.path.join("articles", filename)
23
+    for filename in os.listdir(os.path.join(current_app.root_path, "articles")):
24
+        path = os.path.join(current_app.root_path, "articles", filename)
25 25
         if os.path.isfile(path):
26 26
             files.append(filename)
27 27
     return jsonify(files)