update. 完成分类显示与详情页显示效果

This commit is contained in:
2026-04-01 18:54:42 +08:00
parent 777ca50328
commit 414dc0ee95
23 changed files with 359 additions and 707 deletions
+43 -3
View File
@@ -39,8 +39,48 @@ def seed_articles(count=20):
section = random.choice(subsections)
author = random.choice(users) if users else None
paragraphs = fake.paragraphs(nb=random.randint(3, 8))
content_html = "\n".join([f"<p>{p}</p>" for p in paragraphs])
# --- 2. 构建丰富的 HTML 内容 ---
html_parts = []
# A. 开头:一段引言或摘要
if random.random() > 0.5:
html_parts.append(f"<p><strong>【摘要】</strong> {fake.sentence(nb_words=10)}</p>")
# B. 正文第一段
html_parts.append(f"<p>{fake.paragraph(nb_sentences=4)}</p>")
# C. 随机插入图片占位符 (模拟上传的封面或插图)
# 使用 placehold.co 生成带文字的灰色占位图
img_width = random.choice([600, 800])
img_height = random.choice([300, 400])
img_text = fake.words(nb=3, unique=True)
html_parts.append(
f'<div style="text-align: center; margin: 20px 0;"><img src="https://placehold.co/{img_width}x{img_height}/23418A/FFF?text={"+".join(img_text)}" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);"></div>')
# D. 正文中间段落
html_parts.append(f"<p>{fake.paragraph(nb_sentences=5)}</p>")
# E. 随机插入引用块 (增加排版层次感)
if random.random() > 0.6:
quote = fake.sentence(nb_words=8)
html_parts.append(
f'<blockquote style="border-left: 5px solid #23418A; padding: 10px 20px; margin: 20px 0; background: #f8f9fa; color: #555;"><i>"{quote}"</i></blockquote>')
# F. 随机插入无序列表 (模拟要点陈述)
if random.random() > 0.7:
list_items = "".join([f"<li>{fake.sentence()}</li>" for _ in range(3)])
html_parts.append(f"<ul style='margin: 20px 0; padding-left: 20px;'>{list_items}</ul>")
# G. 加粗和斜体混合段落
p1 = fake.paragraph(nb_sentences=2)
p2 = fake.paragraph(nb_sentences=2)
html_parts.append(f"<p>{p1} <strong style='color: #23418A;'>{fake.words(nb=4, unique=True)}</strong> {p2}</p>")
# H. 结尾
html_parts.append(f"<p>{fake.paragraph(nb_sentences=3)}</p>")
# 拼接最终 HTML
content_html = "\n".join(html_parts)
article = Article.objects.create(
title=fake.sentence(nb_words=random.randint(5, 10))[:-1],
@@ -81,4 +121,4 @@ def seed_articles(count=20):
if __name__ == "__main__":
seed_articles(30)
seed_articles(120)