기본적으로 유효한 img 소스를 반환하는 함수가 있습니다 (예 : https://image.prntscr.com/image/5P0nCp55SKe-WJTKjhCwsg.png )
플라스크를 사용하여 html에 이미지를 표시하려고하면 이미지가 나타나지 않지만 이미지의 작은 아이콘이 표시됩니다. 아이콘을 마우스 오른쪽 버튼으로 클릭하고 "새 탭에서 열기"를 클릭하면 이미지가 표시되지만 HTML에서는 작동하지 않습니다.
내 플라스크 코드 :
from flask import Flask, render_template, redirect, url_for, request
import LightHub # My other script that contains the function
app = Flask(__name__)
@app.route('/')
def index():
return render_template('server.html', source=LightHub.crawl())
app.run(debug=True)
내 HTML 코드 (템플릿 폴더에 있음) :
<html>
<head>
<title>Random Lightshot</title>
<meta charset="utf-8" />
</head>
<body>
<div class="prints" align="middle">
<img src="{{source}}" align="middle">
</div>
</body>
</html>
내가 이것을 시도하면
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('server.html', source='https://image.prntscr.com/image/5P0nCp55SKe-WJTKjhCwsg.png')
효과가있다.
그것은 아마도 LightHub.crawl()
당신이 생각하는 것을 반환하지 않는다는 것을 의미합니다 . 다음과 같이 실행하여 확인할 수 있다고 생각합니다.
assert LightHub.crawl() == 'https://image.prntscr.com/image/5P0nCp55SKe-WJTKjhCwsg.png'
그 주장을 함수에 추가하면 실패 할 것이라고 생각합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다