Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Created August 24, 2012 06:30
Show Gist options
  • Select an option

  • Save flaneur2020/3446645 to your computer and use it in GitHub Desktop.

Select an option

Save flaneur2020/3446645 to your computer and use it in GitHub Desktop.
quixote routing

quixote是一个很落后的框架,使用它只有一个理由,便是我们亲爱的历史原因。

Routing

quixote使用python的类来模拟php的目录结构。

  • _q_exports: 列出这一"目录"下的所有"文件"
  • _q_index(request): 相当于index.php
  • _q_lookup(request, param): 相当于method_missing

嵌套目录的话,记得加一个@property,不然会仅仅返回目录对象本身,而会得到目录对象渲染的结果。

遇到 Page not found: /help/admin/questions/9/comments: object is neither callable nor string 这样的错误,可以尝试在url后面加一个'/'

404

from quixote.errors import TraversalError as NotFoundError

def _q_index(request):
    raise NotFoundError

Cookie

get_request().response.set_cookie(name, value)
get_request().get_cookie(name)

Take care: 在同一请求中get_request().response.set_cookie(name, value)设置cookie之后,get_request().get_cookie(name)不能立即读取这条cookie。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment