ส่วนขยายนี้ช่วยให้คุณสามารถเพิ่มส่วนส่วนหน้าอย่างง่ายลงในแอพ Flask ของคุณ บทความทั้งหมดถูกดึงออกมาจาก WordPress ของ Canonical Back-end ผ่าน JSON API
ส่วนขยายนี้ให้พิมพ์เขียวที่มี 3 เส้นทาง:
ในการติดตั้งส่วนขยายนี้เป็นข้อกำหนดในโครงการของคุณคุณสามารถใช้ PIP ได้
pip3 install canonicalwebteam.blogดูเอกสารสำหรับการติดตั้ง PIP
สำหรับการพัฒนาในท้องถิ่นเป็นการดีที่สุดที่จะทดสอบโมดูลนี้กับหนึ่งในโครงการเว็บไซต์ของเราเช่น ubuntu.com สำหรับข้อมูลเพิ่มเติมให้ทำตามคำแนะนำนี้ (ภายในเท่านั้น)
โมดูลคาดว่าจะมีเทมเพลต HTML ที่ blog/index.html , blog/article.html , blog/blog-card.html , blog/archives.html , blog/upcoming.html และ blog/author.html
ตัวอย่างของเทมเพลตเหล่านี้สามารถดูได้ที่ https://github.com/canonical-websites/jp.ubuntu.com/tree/master/templates/blog
ในแอพของคุณคุณสามารถทำสิ่งต่อไปนี้:
import flask
import talisker . requests
from flask_reggie import Reggie
from canonicalwebteam . blog import BlogViews , build_blueprint , BlogAPI
app = flask . Flask ( __name__ )
Reggie (). init_app ( app )
session = talisker . requests . get_session ()
blog = build_blueprint (
BlogViews (
api = BlogAPI ( session = session ),
)
)
app . register_blueprint ( blog , url_prefix = "/blog" )คุณสามารถปรับแต่งบล็อกผ่านอาร์กิวเมนต์เสริมต่อไปนี้:
blog = build_blueprint (
BlogViews (
blog_title = "Blog" ,
blog_path = "blog" ,
tag_ids = [ 1 , 12 , 112 ],
exclude_tags = [ 26 , 34 ],
per_page = 12 ,
feed_description = "The Ubuntu Blog Feed" ,
api = BlogAPI (
session = session ,
use_image_template = True ,
thumbnail_width = 330 ,
thumbnail_height = 185 ,
),
)
) การทดสอบทั้งหมดสามารถทำงานได้ด้วย ./setup.py test
การโทร API ทั้งหมดจะถูกจับด้วย VCR และบันทึกเป็นอุปกรณ์ติดตั้งในไดเรกทอรี fixtures หากการอัปเดต API การติดตั้งทั้งหมดสามารถอัปเดตได้อย่างง่ายดายโดยเพียงแค่ลบไดเรกทอรี fixtures และทำการทดสอบอีกครั้ง
ในการดำเนินการนี้ Run rm -rf fixtures && ./setup.py test