博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
网站搭建笔记精简版---廖雪峰WebApp实战-Day11:编写日志创建页笔记
阅读量:4166 次
发布时间:2019-05-26

本文共 1993 字,大约阅读时间需要 6 分钟。

今天实现创建博客日志的功能

首先在handlers文件中增加后端功能函数,之后设置前端页面。
代码之后会在github上附上。

handlers

# 验证权限是否正确def check_admin(request):    if request.__user__ is None or not request.__user__.admin:        raise APIPermissionError()# 编写博客创建的api后端函数@post('/api/blogs')async def api_create_blog(request, *, name, summary, content):    check_admin(request)    if not name or not name.strip():        raise APIValueError('name', 'name cannot be empty.')    if not summary or not summary.strip():        raise APIValueError('summary', 'summary cannot be empty.')    if not content or not content.strip():        raise APIValueError('content', 'content cannot be empty.')    blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())    await blog.save()    return blog# 编写mvc将页面显示出来@get('/manage/blogs/create')async def manage_create_blog(request):    return {        '__template__': 'manage_blog_edit.html',        'id': '',        'action': '/api/blogs',        '__user__': request.__user__	}

html

{% extends '__base__.html' %}{% block title %}编辑日志{% endblock %}{% block beforehead %}{% endblock %}{% block content %}    
正在加载...
取消
{% endblock %}

网页测试

网页测试可视化参考博客

转载地址:http://amlxi.baihongyu.com/

你可能感兴趣的文章
Spring MVC 教程,快速入门,深入分析
查看>>
Android 的source (需安装 git repo)
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Ubuntu Navicat for MySQL安装以及破解方案
查看>>
jarFile
查看>>
数学等于号是=那三个横杠是什么符
查看>>
java多线程中的join方法详解
查看>>
idea添加gradle模块报错The project is already registered
查看>>
在C++中如何实现模板函数的外部调用
查看>>
HTML5学习之——HTML 5 拖放
查看>>
HTML5学习之——HTML 5 Canvas vs. SVG
查看>>
HTML5学习之——HTML 5 应用程序缓存
查看>>
HTML5学习之——HTML 5 Web Workers
查看>>
HTML5学习之——HTML 5 Canvas
查看>>
HTML5学习之——HTML5 内联 SVG
查看>>
HTML5学习之——HTML 5 服务器发送事件
查看>>
SVG学习之——HTML 页面中的 SVG
查看>>
SVG 形状学习之——SVG圆形
查看>>
SVG 滤镜学习之——SVG 滤镜
查看>>
mysql中用命令行复制表结构的方法
查看>>