V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  dreampuf  ›  全部回复第 38 页 / 共 51 页
回复总数  1002
1 ... 34  35  36  37  38  39  40  41  42  43 ... 51  
2012 年 7 月 21 日
回复了 levon 创建的主题 Flask 看Flask教程关于Pluggable Views的问题
碰巧在看Flask的实现。实质是将一个Class Instance 转换为一个(或者多个,随Class 的dispatch_request方法的实现而不同)视图。
直接上代码或许比文档更直接。

@classmethod
def as_view(cls, name, *class_args, **class_kwargs):
"""Converts the class into an actual view function that can be
used with the routing system. What it does internally is generating
a function on the fly that will instanciate the :class:`View`
on each request and call the :meth:`dispatch_request` method on it.

The arguments passed to :meth:`as_view` are forwarded to the
constructor of the class.
"""
def view(*args, **kwargs):
self = view.view_class(*class_args, **class_kwargs)
return self.dispatch_request(*args, **kwargs)

if cls.decorators:
view.__name__ = name
view.__module__ = cls.__module__
for decorator in cls.decorators:
view = decorator(view)

# we attach the view class to the view function for two reasons:
# first of all it allows us to easily figure out what class based
# view this thing came from, secondly it's also used for instanciating
# the view class so you can actually replace it with something else
# for testing purposes and debugging.
view.view_class = cls
view.__name__ = name
view.__doc__ = cls.__doc__
view.__module__ = cls.__module__
view.methods = cls.methods
return view


使用举例:

class MethodView(View):
"""Like a regular class based view but that dispatches requests to
particular methods. For instance if you implement a method called
:meth:`get` it means you will response to ``'GET'`` requests and
the :meth:`dispatch_request` implementation will automatically
forward your request to that. Also :attr:`options` is set for you
automatically::

class CounterAPI(MethodView):

def get(self):
return session.get('counter', 0)

def post(self):
session['counter'] = session.get('counter', 0) + 1
return 'OK'

app.add_url_rule('/counter', view_func=CounterAPI.as_view('counter'))
"""
__metaclass__ = MethodViewType

def dispatch_request(self, *args, **kwargs):
meth = getattr(self, request.method.lower(), None)
# if the request method is HEAD and we don't have a handler for it
# retry with GET
if meth is None and request.method == 'HEAD':
meth = getattr(self, 'get', None)
assert meth is not None, 'Unimplemented method %r' % request.method
return meth(*args, **kwargs)
换个环境吧。
2012 年 7 月 16 日
回复了 sofish 创建的主题 分享创造 翻译两个JS相关文档:idiomatic.js 和 Express(Node.js)
感谢!
2012 年 7 月 14 日
回复了 tioover 创建的主题 Django App到底是什么东西!
一个project下面可以有多个app
app是按照网站业务不同的划分,比如博客,论坛,神马的。

https://docs.djangoproject.com/en/1.4/intro/tutorial01/

Projects vs. apps
What's the difference between a project and an app? An app is a Web application that does something -- e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects.
已经卖出去10件了
@colorday 算我一个
2012 年 7 月 12 日
回复了 soulhacker 创建的主题 分享发现 Pythonista: iPad 上(几乎)全功能的 Python IDE
我不要在任何设备上敲代码,太惨了:(
2012 年 7 月 11 日
回复了 kran 创建的主题 问与答 为什么这些平台提供的OAuth接口都不按照标准来??
@forsaken 至少Python的clinet是Copy&paste的Twitter的
2012 年 7 月 7 日
回复了 skydark 创建的主题 Python Python 中的 del 语句在什么场景下是不可或缺的?
del 只是将变量的引用计数手动减一,没有执行实际的GC操作。GC还是Python内部调整
2012 年 7 月 7 日
回复了 HiVPS 创建的主题 站长 KVM VPS年付优惠:最低价格每月只需16元
@dreampuf 求联系方式,想知道访问速度如何
2012 年 7 月 7 日
回复了 HiVPS 创建的主题 站长 KVM VPS年付优惠:最低价格每月只需16元
@HIVPS 操作系统有点少。有没有512测网速的?
2012 年 7 月 2 日
回复了 sll822 创建的主题 服务器 关于idc带宽,备案,ip
@subdragon 同求 soddyque [AT] 163.com Thanks
2012 年 6 月 30 日
回复了 Tuccuay 创建的主题 Chrome Chrome for iOS:evernote.com - 该网站的安全证书不受信任!
将DNS解析改为 8.8.8.8

在我们公司用chrome登录gmail的时候偶尔也会出现这种情况,貌似是“被链接中断”了。
2012 年 6 月 25 日
回复了 cheshirecat 创建的主题 Diablo III DiabloDPS.com:战力评定
评定清空默认
DPS 9437 血量 12344 抗性 432 护甲 5086
综合战力 : 6.06 ~ 级别评定 : 渣 ~ EHP : 76537


伤不起。。
2012 年 6 月 23 日
回复了 ihciah 创建的主题 Google App Engine GAE的urllib2或者urlfetch如何保存cookie?
Google 搜索 "urllib2 cookie"

Python urllib2 doc
http://docs.python.org/library/urllib2.html

主要方法是通过urllib2.build_opener一个工厂函数生成可持续会话的Reuqest(通过urllib2.HTTPCookieProcessor等保存Headers)
2012 年 6 月 1 日
回复了 Kael 创建的主题 Diablo III 有人过炼狱第二幕了么?
@Kael 欢乐极了!
2012 年 5 月 30 日
回复了 txx 创建的主题 Android 入手三儿子,请教大伙儿都安装什么应用了?
看了下店铺的文案,欢乐爆了。



======================

http://img04.taobaocdn.com/imgextra/i4/821301387/T2uKGIXhdaXXXXXXXX_!!821301387.jpg

大象,大象,

你的鼻子为什么这么长~

NOTE完全算的上手机里的大象了

三爽也蛮有自知之明

广告就是拿一头智商爆表的大象和一只萌妹子做的

话说GEEK圈的评论真TM不能信

出来就喷

什么拿出去接电话太SB

什么裤兜里都放不下还叫什么手机

三爽瞬间拿出500W的销量打你们脸

你们懂不懂公车上看到一个穿白色衣服的萌妹子用白色版的NOTE是多美的场景

人家才没有裤兜,人家都是带着里面装着各种男人们无法理解的杂七杂八东西的次元袋出门的好不好。

人家就是喜欢越大越好懂不懂

懂不懂
@ayanamist 是的,UE经过一些设置也能够很明显的区分这些问题。
2012 年 5 月 28 日
回复了 liuyu2629875 创建的主题 随想 又到一年六月伤感离别季。。。
确定好自己方向,无论是否有一份好的实习(工作)
如果没有女友,向自己最倾心的女孩表白,哪怕失败
打盘Dota(CS),吃一顿,醉一宿

打包,走人


离别的美,应该只有事后回味才知道吧
1 ... 34  35  36  37  38  39  40  41  42  43 ... 51  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5238 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 41ms · UTC 07:55 · PVG 15:55 · LAX 00:55 · JFK 03:55
♥ Do have faith in what you're doing.