當前位置: 首頁>>代碼示例>>Python>>正文


Python PageData.page方法代碼示例

本文整理匯總了Python中main.PageData.page方法的典型用法代碼示例。如果您正苦於以下問題:Python PageData.page方法的具體用法?Python PageData.page怎麽用?Python PageData.page使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在main.PageData的用法示例。


在下文中一共展示了PageData.page方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search

# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import page [as 別名]
def search():
    """
    :URL: /item/search?page=<page>&type=<query type>&limit=<max results>&query=<search query>&sort=<sort type>

    :Method: GET

    :Query Types:
        * item - Item Search
        * user - User Search

    :Sort Types:
        * name - Alphabetical by name
        * added - By added date, latest first
        * modified - Last modified

    :Sample Response: Setting the accept:application/json header will return JSON. 

    .. code-block:: javascript

    {
        "limit": 2,
        "num_pages": 4,
        "num_results": 8,
        "query": "Cascadia",
        "results": [
            {
                "added": "2016-05-22 17:52:36",
                "body": "Blue/White (Cascadia Fringe, Gisele Currier Memorial Fundraiser)",
                "description": 460,
                "images": [
                    388,
                    389
                ],
                "modified": "2016-05-24 22:45:33",
                "name": "No Pity MLS Blue White Fringe (Cascadia Fringe) 2012",
                "uid": 362
            },
            {
                "added": "2016-05-22 17:02:15",
                "body": "",
                "description": 317,
                "images": [
                    364,
                    365
                ],
                "modified": "2016-05-22 17:02:15",
                "name": "Cascadia",
                "uid": 350
            }
        ]
    }
    """

    pd = PageData()
    pd.search_type = request.args.get('type')
    pd.query = request.args.get('query')
    pd.limit = request.args.get('limit')
    pd.page = request.args.get('page')
    pd.sort = request.args.get('sort')

    try:
        if not pd.limit:
            pd.limit = 20
        else:
            pd.limit = int(pd.limit)

        if not pd.page:
            pd.page = 1
        else:
            pd.page = int(pd.page)
    except ValueError:
        return page_not_found()

    if pd.search_type == "items":
        return item_search(pd)
    elif pd.search_type == "users":
        return user_search(pd)
    elif pd.search_type == "tags":
        return tag_search(pd)
    else:
        pd.search_type = "items"
        return item_search(pd)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:84,代碼來源:search.py


注:本文中的main.PageData.page方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。