V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Hualin
V2EX  ›  Python

第一次做网页开发 flask 新手 记下一点感想 大家可以吐槽板砖或者指正

  •  
  •   Hualin · 2013-01-28 20:59:14 +08:00 · 3595 次点击
    这是一个创建于 4106 天前的主题,其中的信息可能已经有所发展或是发生改变。
    开发的时候我用 markdown 记录了一点体会,随着时间的推移,其中一些可能是错的。过去没学过任何网页开发的相关技术(我大学是怎么混的??),这次可算是摸着石头过河了,有一些可能是开发常识,我没法找到相关的入门读物,只能靠试琢磨出来一点:

    DEVELOP NOTE
    ===

    # Jan 20 2013
    + in flask, `flask.g` is just something global, which could be refered anywhere like Jinja Template and python project files. It is actually a nothing but a global variable defined in Flask. So just store anything you want there, but do remember the state and reference order of flask.g since it could be changed over time.
    + `endpoint`: Flask itself assumes the name of the view function as `endpoint`.
    + `flask.url_for(endpoint, **values)`, Generates a URL to the given endpoint with the method provided.
    + URL, ENDPOINT and TEMPLATE file name are three different things that are combined together.
    + flask view class is only useful when you need this view to be pluggable to other model or from my understanding now, to other app. sometime it could make things tricky and complex, as the functional view is flexible enough and short.

    # Jan 21 2013
    + Accessing rule of each occupation could be defined for global access control.
    + in flask, `render_template` and `redirect` are not that dramatically different as the names suggest, to me at least, regardless their calling siganiture. (it is wrong)

    # Jan 23 2013
    + the `block` in data base should always remain invisible to users.

    # Jan 27 2013
    + in flask, the HTML is the final view to the user, usually, the develop is view-focusing rather than model-focusing, since it is not a main problem at now. if one HTML view is so much different from another, they should be end up with differnent HTML view, if their logical view share a lot in common, they could share a same view function.
    + flask tries to enforce the opinion that less logic in templates is a good thing.
    + view function should assist jinja to have the logic, it should have all things ready and return them, which is the basic design of `render_template()` calling. thus, a view function should have an 'image' data structure of the corresponding template view.
    + in utility.py query_db and query_db2 are different in return object, the former one returns query object as a dict, while the later one returns a sqlite3.row object. I do not understand the code yet, but the utility function could be used in the future.

    懒得翻译了 有很多语法错误。。。。。。。。。
    8 条回复    1970-01-01 08:00:00 +08:00
    Sherlockhlt
        1
    Sherlockhlt  
       2013-01-28 22:26:10 +08:00 via iPad
    想问你用什么编辑器写markdown的?
    Hualin
        2
    Hualin  
    OP
       2013-01-28 22:28:15 +08:00
    @Sherlockhlt 这算是吐槽吗 他哥 我桑心了
    crossmaya
        3
    crossmaya  
       2013-01-28 22:30:14 +08:00
    这是炫耀英语贴吗?
    scarlex
        4
    scarlex  
       2013-01-28 22:34:41 +08:00
    本来想看看flask的心得的……结果进来之后一点欲望也没有了……
    想问问楼主学flask多久了?不知道有web开发经验(之前都用django)学flask要多久?
    Sherlockhlt
        5
    Sherlockhlt  
       2013-01-28 22:39:01 +08:00 via iPad   ❤️ 1
    @Hualin
    非吐槽,真的想知道呢
    Hualin
        6
    Hualin  
    OP
       2013-01-28 22:54:46 +08:00
    @Sherlockhlt sublime text (windows ) or mou (mac)
    Hualin
        7
    Hualin  
    OP
       2013-01-28 22:55:47 +08:00
    @crossmaya 我要shi了 你不觉得搞开发用英文做笔记比较方便吗,不用换输入法 杜绝所有乱码 好搜索 好表达?
    Hualin
        8
    Hualin  
    OP
       2013-01-28 22:57:49 +08:00
    @scarlex 桑心了,快一个月,我加入了一个web app 的项目,有 deadline 和 milestone ,然后逼着自己用 flask
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1346 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:51 · PVG 01:51 · LAX 10:51 · JFK 13:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.