플라스크에 (마크 다운) 문자열을 반환하기 만하면됩니다.
@app.route("/raw/", methods=['GET'])
def sometext():
return "This is an **example**"
## Main procedure
if __name__ == "__main__":
app.run(debug=True, port=8000)
pandoc에 직접 전화 ( pandoc http://localhost:8000/raw
)하거나를 사용 subprocess
하면 문제가 없습니다.
import subprocess, os
url = "http://localhost:8000/raw"
pbody = subprocess.run(["pandoc", url], check=True, stdout=subprocess.PIPE)
print(pbody.stdout.decode())
하지만 플라스크 메서드 내에서 pandoc을 호출하면 :
@app.route("/get", methods=['GET'])
def index():
url = "{}".format(url_for('sometext', _external=True))
pbody = subprocess.run(["pandoc", url], check=True, stdout=subprocess.PIPE, universal_newlines=True)
print("***Error: ", pbody.stderr)
return pbody.stdout
그런 다음 액세스 http://localhost:8000/get
하면 pandoc에서 Responsetimeout 오류가 발생합니다.
pandoc: HttpExceptionRequest Request {
host = "localhost"
port = 8000
secure = False
requestHeaders = []
path = "/raw/"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
ResponseTimeout
참조 : 플라스크 API의 url_for
내가 기억하는 것처럼 Flask http 서버는 단일 스레드이므로 '/ get'요청을 처리하는 동안 '/ raw'요청을 처리 할 수 없습니다.
다른 SO 질문에 대한 답변 은 app.run(threaded=True)
개인적인 용도로 충분할 수 있음을 제안 합니다. 프로덕션 용도의 경우 nginx 또는 apache와 같은 실제 웹 서버를 고려해야합니다.
그럼에도 불구하고 pandoc이 그것을 지원한다고 가정하면 (나는 모르겠다) markdown 입력을 pandoc stdin으로 보내고 여분의 HTTP 요청을 완전히 피할 수 있습니다. (unested)
markdown = StringIO("This is an **example**")
pbody = subprocess.run(["pandoc"], check=True, stdin=markdown, stdout=subprocess.PIPE, universal_newlines=True)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다