1富文本编辑框的使用
<script src="/static/kindeditor/kindeditor-all.js"></script>
<script>
KindEditor.ready(function (K) {
window.editor = K.create('#content', { #文本域的id
'100%',
height: '400px',
resizeType: 0, #格式禁止拖拽等
uploadJson: '/add_image/', #上传图片请求
extraFileUploadParams: {
csrfmiddlewaretoken: '{{ csrf_token }}' #可以携带参数
}
});
});
</script>
2.个人站点urls
url(r'^(?P<site>w+)/(?P<group>category|tag|archive)/(?P<key>.+)$', views.site), #返回分组信息
url(r'^(?P<site>w+)$', views.site), #通过url直接访问
url(r'^(?P<site>w+)/$', views.site)
3.登录装饰器导入
from django.contrib.auth.decorators import login_required,
4.导入相关模块
from django.db.models import Count
from django.db.models.functions import TruncMonth
# 添加文章正文图片
def add_image(request):
print(request.FILES)
path = 'media/img'
if not os.path.exists(path):
os.mkdir(path)
file = request.FILES.get('imgFile', None)
img_path = path + "/" + file.name
with open(img_path, 'wb') as f:
for line in file:
f.write(line)
return JsonResponse({
"error": 0,
'url': '/' + img_path
})
soup = BeautifulSoup(content, 'html.parser')
desc = soup.text.strip()[0:100] # 解析后数据存放在soup.text
def site(request, site, group=None, key=None):
from bs4 import BeautifulSoup