Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 19

小虎888/MyDjangoBlog
Paused

forked from J.sky/MyDjangoBlog
Paused
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (2)
master
dev
master
Branches (2)
master
dev
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (2)
master
dev
17python
/
MyBlog
/
context_processor.py
17python
/
MyBlog
/
context_processor.py
context_processor.py 2.01 KB
Copy Edit Raw Blame History
#coding=utf-8
from random import shuffle
import datetime
from django.conf import settings as original_settings
from blog.models import UserProfile, Siteinfo, Category, Article #导入站长及站长资料model
def site_info(request):
'''站长资料、网站资料,所有分类上下文'''
userinfo = UserProfile.objects.get(pk=1)#站长资料
siteinfo = Siteinfo.objects.get(pk=1)#获取站点信息
categorys = Category.objects.all().order_by('category_sort_id')#获取所有分类
hot_articles = Article.objects.all().order_by('-article_click')[:10]#获取热门文章
ac_count = Article.objects.count()#获得文章数量
d1 = datetime.datetime.now()
d2 = datetime.datetime(2020, 4, 20)
killpy2 = (d2 - d1).days
acs= Article.objects.all()
ac_click = 0
for ac in acs:
ac_click += int(ac.article_click)
# datetimes() 方法返回一个 python 的 datetimes 对象列表
# 对应着每篇文章的发表时间
# month 表示精确到月份,DESC 表示降序排列
dates = Article.objects.datetimes('article_create_time', 'month', order='DESC')
# 获取文章标签
l = Article.objects.values("article_tag").distinct().filter(article_type='2')
tags = []
for k in l:
templist = k['article_tag'].split(' ')
# print(templist)
for item in templist:
if item not in tags:
tags.append(item)
shuffle(tags)
tagcss =['am-radius','am-badge-primary','am-badge-secondary','am-badge-success','am-badge-warning','am-badge-danger']
return {'userinfo':userinfo, 'siteinfo':siteinfo, 'categorys':categorys,
'dates':dates, 'alltags':tags, 'tagcss':tagcss,
'hot_articles':hot_articles,'ac_count':ac_count,'killpy2':killpy2,'ac_click':ac_click,}
'''
这里遇到了一个小小坑,当上下文管理器中定义并返回了一个变量,如果他程序中的视图中的变量重名,那么变量值就会变成视图中的值。
所以这里的tags需要改一个名字。
'''
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

MyDjangoBlog是基于Django搭建的个人blog,欢迎喜爱Django加入进来,交个朋友。
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/tiger_888/17python.git
git@gitee.com:tiger_888/17python.git
tiger_888
17python
MyDjangoBlog
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /