Background processing :

views.py
def blog_time(request, year, month): change_info(request) postsAll =
Articles.objects.all().filter(status=" Effective ").order_by('-timestamp')
blog_list_greats =
Articles.objects.filter(status=" Effective ").order_by("-greats")[0:10]
blog_list_comments =
Articles.objects.filter(status=" Effective ").order_by("-comments")[0:10] blog_lists =
Articles.objects.filter(timestamp__year=year, timestamp__month=month,
status=" Effective ").order_by('-timestamp') paginator = Paginator(blog_lists, 10) #
paging , each page 10 Data page = request.GET.get('page') try: contacts = paginator.page(page)
# contacts by Page object ! except PageNotAnInteger: # If page is not an integer,
deliver first page. contacts = paginator.page(1) except EmptyPage: # If page is
out of range (e.g. 9999), deliver last page of results. contacts =
paginator.page(paginator.num_pages) comments = Comment.objects.count() tags =
Tag.objects.all() count = Articles.objects.count() categorys =
Category.objects.all() jia = Jia.objects.get(id=1) articles =
Articles.objects.all().filter(status=" Effective ") year_month = set() # Set collection , No duplicate elements for
a in articles: year_month.add((a.timestamp.year, a.timestamp.month)) #
Put the year of each article , Months are added to the collection as tuples counter = {}.fromkeys(year_month, 0) # As tuple key, Initialize dictionary for
a in articles: counter[(a.timestamp.year, a.timestamp.month)] += 1 # Count the number of articles by month
year_month_number = [] # Initialization list for key in counter:
year_month_number.append([key[0], key[1], counter[key]]) #
Translate dictionary into ( year , month , number ) Tuples are lists of elements year_month_number.sort(reverse=True) # sort
print(year_month_number) context = { 'tags': tags, 'contacts': contacts,
'comments': comments, 'categorys': categorys, 'blog_list_greats':
blog_list_greats, 'blog_list_comments': blog_list_comments, 'blog_category':
blog_category, 'jia': jia, 'year_month_number': year_month_number } return
render(request, 'archive.html', context=context)
This section is a bit redundant , It mainly searches articles according to the year and year , Open the corresponding page

urls.py
url(r'^list/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/$', views.blog_time),
Then is the background logic of the home page display :

views.py
def blog_index(request): # post = request.get_post(Articles, pk=pk)
change_info(request) blog_lists =
Articles.objects.filter(status=" Effective ").order_by("-timestamp")[0:10] # Get all data
blog_list_head =
Articles.objects.filter(status=" Effective ").filter(istop=1).order_by("-timestamp")[0:5]
# obtain 5 Head 5 individual blog_list_up =
Articles.objects.filter(status=" Effective ").filter(istop=2).order_by("-timestamp")[0:4]
# obtain 2, above 4 individual blog_list_middle =
Articles.objects.filter(status=" Effective ").order_by('-comments')[0:2] # obtain 2, The two in the middle
blog_list_down = Articles.objects.filter(status=" Effective ").order_by('-greats')[0:2]
# obtain 2, The next two blog_list_news =
Articles.objects.filter(status=" Effective ").order_by("-timestamp")[0:10] # obtain 3 recent
posts blog_list_views =
Articles.objects.filter(status=" Effective ").order_by('-views')[0:10] # Click ranking
blog_list_hots = Articles.objects.filter(status=" Effective ").order_by('-views')[0:4] #
Click ranking blog_list_greats =
Articles.objects.filter(status=" Effective ").order_by('-greats')[0:10] # Guess you like it
blog_list_comments =
Articles.objects.filter(status=" Effective ").order_by('-comments')[0:10] # Recommended by bloggers
blog_list_large =
Articles.objects.filter(status=" Effective ").order_by('-timestamp')[0:1] # obtain 1, The biggest one
articles = Articles.objects.all().filter(status=" Effective ") year_month = set() #
Set collection , No duplicate elements for a in articles: year_month.add((a.timestamp.year,
a.timestamp.month)) # Put the year of each article , Months are added to the collection as tuples counter = {}.fromkeys(year_month, 0)
# As tuple key, Initialize dictionary for a in articles: counter[(a.timestamp.year,
a.timestamp.month)] += 1 # Count the number of articles by month year_month_number = [] # Initialization list for key in
counter: year_month_number.append([key[0], key[1], counter[key]]) #
Translate dictionary into ( year , month , number ) Tuples are lists of elements year_month_number.sort(reverse=True) # sort
print(year_month_number) tags = Tag.objects.all() count =
Articles.objects.count() pagelist = round(count / 3) pl = [] for i in
range(pagelist): pl.append(i + 1) print((pl)) comment_list =
Comment.objects.count() note = Note.objects.get(id=str(random.randint(1,
Note.objects.count()))) print(note.noteimage) categorys =
Category.objects.all() catcharts = {} for cats in categorys: catnums =
Articles.objects.filter(category=cats.id).filter(status=' Effective ').count()
catcharts[cats.name] = catnums django =
Articles.objects.filter(category=1).filter(status=' Effective ').count() python =
Articles.objects.filter(category=2).filter(status=' Effective ').count() mysql =
Articles.objects.filter(category=3).filter(status=' Effective ').count() leetcode =
Articles.objects.filter(category=4).filter(status=' Effective ').count() other =
Articles.objects.filter(category=5).filter(status=' Effective ').count() java =
Articles.objects.filter(category=6).filter(status=' Effective ').count() javascript =
Articles.objects.filter(category=7).filter(status=' Effective ').count() maxmap =
max(django, python, leetcode, mysql, other, java, javascript) minmap =
min(django, python, leetcode, mysql, other, java, javascript) allvisit =
VisitNumber.objects.first() jia = Jia.objects.get(id=1) try: version =
models.Version.objects.filter(version_time=datetime.datetime.now().strftime('%Y-%m-%d')).values(
'version_content') versions = [item[key] for item in version for key in
item][0].split(";") except IndexError as err: print("error", err) version =
models.Version.objects.order_by('-version_time')[0:1].values('version_content')
versions = [item[key] for item in version for key in item][0].split(";")
'''else: version = models.Version.objects.all()[0:1].values('version_content')
versions = [item[key] for item in version for key in item][0].split(";")'''
context = { 'blog_list': blog_lists, 'blog_list_views': blog_list_views,
'blog_list_greats': blog_list_greats, 'blog_list_comments': blog_list_comments,
'tags': tags, 'pagelists': pl, 'comment_list': comment_list, 'note': note,
'categorys': categorys, 'count': count, 'blog_list_five': blog_list_head,
'blog_list_up': blog_list_up, 'blog_list_middel': blog_list_middle,
'blog_list_down': blog_list_down, 'blog_list_three': blog_list_news,
'blog_list_hots': blog_list_hots, 'blog_list_large': blog_list_large, 'django':
django, 'python': python, 'mysql': mysql, 'leetcode': leetcode, 'other': other,
'java': java, 'javascript': javascript, 'max': maxmap, 'min': minmap,
'versions': versions, 'allvisit': allvisit, 'catcharts': catcharts, 'jia': jia,
'year_month_number':year_month_number, } return render(request,
'Jiaindex.html', context=context) # return Jiaindex.html page
The main part is :
articles = Articles.objects.all().filter(status=" Effective ") year_month = set() #
Set collection , No duplicate elements for a in articles: year_month.add((a.timestamp.year,
a.timestamp.month)) # Put the year of each article , Months are added to the collection as tuples counter = {}.fromkeys(year_month, 0)
# As tuple key, Initialize dictionary for a in articles: counter[(a.timestamp.year,
a.timestamp.month)] += 1 # Count the number of articles by month year_month_number = [] # Initialization list for key in
counter: year_month_number.append([key[0], key[1], counter[key]]) #
Translate dictionary into ( year , month , number ) Tuples are lists of elements year_month_number.sort(reverse=True) # sort
At this point, a list is passed in to the front end :
[[2019, 7, 5], [2019, 6, 8], [2019, 5, 2], [2019, 4, 3], [2019, 3, 11], [2019,
2, 34]]
And then the front end html part :
<div class="widget widget_categories version-ii wow fadeInUp"
data-wow-delay="0.4s"> <header class="widget-head"> <h3>Time</h3> </header>
<ul> {% for i in year_month_number %} <li class="cat-item
cat-item-1"><!--span><a href="#">- Lifestyle</a></span--><span><a
href="/JiaBlog/list/{{ i.0 }}/{{ i.1 }}" target="_blank">- {{ i.0 }} year {{ i.1
}} month ---({{ i.2 }})</a></span></li> {% endfor %} </ul> </div>
 

Technology
©2019-2020 Toolsou All rights reserved,
c Language to achieve mine clearance Games and mine source code Node.js Middle template engine 3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! The situation of receiving and receiving multi-path git It's set correctly ssh, But it still prompts Permission denied (publickey) new iPhone I won't support it 5G Will lead to further decline in shipment C# Sorting method of Chinese Dictionaries 10909 rice ! Chinese fighter successfully landed in Mariana Trench MySQL8.0MGR Single owner / Multi master installation and switching Java Poor reflection performance ?