728x90
반응형

검색 결과 페이지에 출력하기(grid 사용)

 

server.py

@app.route("/report")
def report():
    word = request.args.get("word") 
    if word:
        word = word.lower()
        existingNews = db.get(word)
        if existingNews:
            news = existingNews
        else:
            news = get_news(word)
            db[word] = news
    else:  
        return redirect("/")  
    return render_template(
        "report.html", 
        searchingBy=word, 
        resultNumber=len(news),
        news=news
    )

 

report.html

<div class="about--banner">
	<h2>result</h2>
	<h3>Found {{resultNumber}} results for: {{searchingBy}}</h3>
	<section>
		<h4>Title</h4>
		<h4>Company</h4>
		<h4>Date</h4>
		<h4>Link</h4>
		{% for result_news in news%}
			<span>{{result_news.title}}</span>
			<span>{{result_news.company}}</span>
			<span>{{result_news.date}}</span>
			<a href="{{result_news.link}}" target="_blank">Go to page</a>
		{% endfor %}
	</section>
</div>

 

출력결과

 

반응형
복사했습니다!