update. 完善基础信息配置以及页面链接处理

This commit is contained in:
2026-04-02 00:49:21 +08:00
parent b8d53a4c2e
commit 66dd4916d1
17 changed files with 218 additions and 275 deletions
+8 -7
View File
@@ -1,4 +1,4 @@
from django.urls import path, include
from django.urls import path, include, re_path
from front import views
@@ -7,11 +7,12 @@ app_name = 'front' # 可选,用于命名空间(如 {% url 'main:index' %}
urlpatterns = [
path('', views.index, name='index'),
path('<str:main>.html', views.section, name='section'),
path('<str:main>/list.html', views.main_article_list, name='main_list'),
path('<str:main>/list/<str:sub>.html', views.sub_article_list, name='sub_list'),
path('about/', views.about, name='about'),
path('news/', views.news, name='news'),
path('list/news.html', views.main_news_list, name='news_main'),
path('list/<str:main>.html', views.main_article_list, name='main_list'),
path('list/<str:main>/<str:sub>.html', views.sub_article_list, name='sub_list'),
path('news/<int:pk>.html', views.news_detail, name='news_detail'),
path('about', views.about, name='about'),
path('news/<str:sub>.html', views.sub_news_list, name='news_list'),
path('article/<int:pk>.html/', views.article_detail, name='article_detail'),
path('news/<int:pk>.html/', views.news_detail, name='news_detail'),
re_path('news$', views.news, name='news'),
path('article/<int:pk>.html', views.article_detail, name='article_detail'),
]
+9 -8
View File
@@ -121,12 +121,12 @@ def news(request):
sections = NewsSection.objects.filter(visible=True).all().order_by('order')
section_data = [
{
"key": section.code,
"key": sec.code,
"data": {
section.title: section.news_set.filter(is_published=True)[:7],
sec.title: sec.news_set.filter(is_published=True)[:7],
}
}
for section in sections
for sec in sections
]
context = {
@@ -161,19 +161,20 @@ def section(request, main):
def main_news_list(request):
logger.info("正在访问新闻中心")
news_list = News.objects.all()
news_sections = NewsSection.objects.all()
news_list = News.objects.filter(is_published=True).all()
news_sections = NewsSection.objects.filter(visible=True).all()
# 分页参数
news_list = custom_pagination(news_list, request)
return render(request, 'front/list.html', {
context = {
'main_section': {
'title': '新闻中心',
'code': 'news'
},
'articles': news_list,
'sections': news_sections,
})
}
return render(request, 'front/list.html', context)
def custom_pagination(news_list, request):
@@ -195,7 +196,7 @@ def custom_pagination(news_list, request):
def sub_news_list(request, sub: str):
logger.info(f"正在访问 {sub}")
sections = NewsSection.objects.all().order_by('order')
sections = NewsSection.objects.filter(visible=True).order_by('order')
logger.info(f"新闻板块: {sections}")
main_section = {
'title': '新闻中心',