• 廖大python实战教程第七天


    MVC框架

    使用模板

    MVC的全名是Model View Controller,是模型-视图-控制器的缩写,是一种软件设计典范。使用MVC的目的是使M和V的代码分离,从而使一个程序可以有不同的表现形式。

    各种错误

    这个地方在所难免。实在没想到用IDE照着敲都会有一些不注意的小细节错误。

    一开始页面是 404 Not Found。等查明原因后发现add_routes()函数没有执行,里面有三四处错误。一般来说,404 Not Found的日志不会有这么一句::add route GET / => index(request),从此处我感受到了日志的重要性。

    后来还有一个错误,和评论区很多人一样是 500 Internal Server Error Server got itself in trouble,出现这种错误一般是handlers.py照着廖大教程上copy(嗯,如果不是copy你会发现错误的)。因为先前使用的是asnyc/await标记实现异步操作,所以此处也应该改为这种方式。

    正确的日志

    意识到日志的重要性,我就想着发上来,让有疑惑的人对比一下。

    INFO:root:create database connection pool...
    INFO:root:init jinja2...
    INFO:root:set jinja2 template path: C:UsersChanWunsamawesome-python3-webappwww	emplates
    INFO:root:found model: User (table: users)
    INFO:root:  found mapping: id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: email ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: passwd ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: admin ==> <BooleanField, boolean:None>
    INFO:root:  found mapping: name ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: image ==> <StringField, varchar(500):None>
    INFO:root:  found mapping: created_at ==> <FloatField, real:None>
    INFO:root:found model: Blog (table: blogs)
    INFO:root:  found mapping: id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_name ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_image ==> <StringField, varchar(500):None>
    INFO:root:  found mapping: name ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: summary ==> <StringField, varchar(200):None>
    INFO:root:  found mapping: content ==> <TextField, text:None>
    INFO:root:  found mapping: created_at ==> <FloatField, real:None>
    INFO:root:found model: Comment (table: comments)
    INFO:root:  found mapping: id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: blog_id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_id ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_name ==> <StringField, varchar(50):None>
    INFO:root:  found mapping: user_image ==> <StringField, varchar(500):None>
    INFO:root:  found mapping: content ==> <TextField, text:None>
    INFO:root:  found mapping: created_at ==> <FloatField, real:None>
    INFO:root:add route GET / => index(request)
    INFO:root:add static /static/ => C:UsersChanWunsamawesome-python3-webappwwwstatic
    INFO:root:server started at http://127.0.0.1:9000...
    INFO:root:Request: GET /
    INFO:root:Response handler...
    INFO:root:call with args: {'request': <Request GET / >}
    INFO:root:SQL: select `id`, `email`, `passwd`, `admin`, `name`, `image`, `created_at` from `users`
    INFO:root:rows returned: 2
    INFO:aiohttp.access:127.0.0.1 - - [26/Jan/2018:12:17:38 +0000] "GET / HTTP/1.1" 200 402 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
    INFO:root:Request: GET /
    INFO:root:Response handler...
    INFO:root:call with args: {'request': <Request GET / >}
    INFO:root:SQL: select `id`, `email`, `passwd`, `admin`, `name`, `image`, `created_at` from `users`
    INFO:root:rows returned: 2
    INFO:aiohttp.access:127.0.0.1 - - [26/Jan/2018:12:18:08 +0000] "GET / HTTP/1.1" 200 402 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
    INFO:root:Request: GET /
    INFO:root:Response handler...
    INFO:root:call with args: {'request': <Request GET / >}
    INFO:root:SQL: select `id`, `email`, `passwd`, `admin`, `name`, `image`, `created_at` from `users`
    INFO:root:rows returned: 2
    INFO:aiohttp.access:127.0.0.1 - - [26/Jan/2018:12:18:10 +0000] "GET / HTTP/1.1" 200 402 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
    

    嗯,出现错误,不要怀疑教程,好好检查一下handlers,coreweb,app这几个文件。

  • 相关阅读:
    分页字符串帮助类
    CSS--九宫格滑过变红色
    css --- flex布局
    MongoDB数据库
    background属性和position属性
    js------this关键字
    js程序-- DNA相关问题
    express4.X--中间件
    CSS——<img>标签图片适配居中问题
    git学习———建立git仓库上传github和从github上下载工程
  • 原文地址:https://www.cnblogs.com/ChanWunsam/p/10018268.html
Copyright © 2020-2023  润新知