yumaojun03 / blog-python-app Goto Github PK
View Code? Open in Web Editor NEW编写一个博客 web app,从中实现一个自己的web 框架
编写一个博客 web app,从中实现一个自己的web 框架
import utils 我用pip安装了这个包但是依然有错误
File "/home/work/blog-python-app/www/transwarp/web.py", line 789, in set_header
self._headers[key] = utils.to_str(value)
AttributeError: 'module' object has no attribute 'to_str'
blog-python-app/www/transwarp/db.py
Line 345 in 8a92f60
cols, args = zip(*kw.iteritems())
中*kw
是不是应该改成kw 以便使用iteritems()方法提取k w ?sql='insert into
%s(%s) values(%s)'%(table,','.join(['
%s'% col for col in cols]),','.join(['?' for i range(len(cols))]))中 第二个
%s是要插入的列 第三个
%s是要插入的值 ,所以 ','.join(['
%s'% col for col in cols]),','.join(['?' for i range(len(cols))])
是不是反了?3.还有一个弱智的问题,第一个%s使用'``'
符号是什么意思?
还请帮忙,小白看不懂
@with_connection
def _update(sql, *args):
"""
执行update语句,返回行数
"""
global _db_ctx
cursor =None
sql = sql.replace('?','%s')
logging.info('SQL: %s, ARGS: %s' % (sql, args))
try:
cursor = _db_ctx.connection.cursor()
cursor.execute(sql, args)
r = cursor.rowcount
if _db_ctx.transactions == 0:
# no transaction enviroment:
logging.info('auto commit')
_db_ctx.connection.commit()
return r
finally:
if cursor:
cursor.close()
在这个函数中有两点疑问,希望得到雪峰老师的指导
``
for k, v in defaults.iteritems():
params[k] = kw.pop(k, v) # dict.pop(key, default_value) 如果用户未设定,则使用默认值。
params.update(kw)
#上面这段代码不是可以用下面这两句写吗。
params.update(defalults)
params.update(kw)
``
2、问题
``
engine = _Engine(lambda: mysql.connector.connect(**params))
这里为什么要用lambda ? 本来这句不就是调用一次mysql.connector.connect方法吗。
``
文章上面写的加载静态文件如下:
templates或者static目录下的资源文件
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/md5.js"></script>
但是这样加载是不行的,我自己试过:
D:\python_wrokplace\app-python\app>python pymintor.py wsgiapp.py
[Monitor] Watching directory D:\python_wrokplace\app-python
.....
127.0.0.1 - - [12/Jun/2016 19:23:35] "GET /static/site.css HTTP/1.1" 404 48
html文件都在templates文件加下,后面我使用绝对目录:
这样加载也不行; flask框架中,有url_for()函数;这个框架中如何实现?logging.info('[CONNECTION] [CLOSE] connection <%s>...' % hex(id(connection)))
connection --> _connection
logging.info('[CONNECTION] [CLOSE] connection <%s>...' % hex(id(_connection)))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.