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

你可能感兴趣的文章
extern"C"的使用
查看>>
使用nm命令获取linux的可执行文件里或动态库中的所有函数名称
查看>>
关于free命令 内存的详细介绍以及如何手动释放内存
查看>>
Linux使用free命令buff/cache过高
查看>>
如何定义结构体变量及如何使用
查看>>
c语言中 有无bool 这个变量
查看>>
SVN错误:cannot show diff because of inconsistent of newline in the file 的解决方法
查看>>
回调函数的使用总结(非常重要)
查看>>
头文件.H使用注意事项总结
查看>>
无论是static还是非static的局部变量,每个线程都是私有的,其他线程不会对其进行干扰。
查看>>
linux下守护进程启动一个新应用进程的区别system、open和execl (execl在Ubuntu和linux执行的区别)
查看>>
memcpy使用函数注意(如果格式不一样如:memcpy(&A[0],(char *)&B,4))
查看>>
一个结构体的双指针和一个结构体的数组指针使用例子(都可以)
查看>>
多个.C和.H文件的相互调用以及变量的跨文件使用
查看>>
转:Linux 各种BCD时间与Unix时间戳格式转换
查看>>
串口阻塞和非阻塞
查看>>
共用体位域的高低位
查看>>
linux的添加网关 查看网关等信息
查看>>
浅谈C++类中的公有和私有
查看>>
std::string用法总结
查看>>