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


Python httpexceptions.HTTPFound方法代碼示例

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


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

示例1: register_post

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def register_post(request: Request):
    email = request.POST.get('email')
    name = request.POST.get('name')
    password = request.POST.get('password')

    if not email or not name or not password:
        return {
            'email': email,
            'name': name,
            'password': password,
            'error': 'Some required fields are missing.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    # create user
    user = user_service.create_user(email, name, password)
    cookie_auth.set_auth(request, user.id)

    return x.HTTPFound('/account')


# ################### LOGIN ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:24,代碼來源:account_controller.py

示例2: login_post

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def login_post(request: Request):
    data = request_dict.create(request)
    email = data.email
    password = data.password

    user = user_service.login_user(email, password)

    if not user:
        return {
            'email': email,
            'password': password,
            'error': 'The user could not found or the password is incorrect.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    cookie_auth.set_auth(request, user.id)
    return x.HTTPFound('/account')


# ################### LOGOUT ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:22,代碼來源:account_controller.py

示例3: item_add

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def item_add(request):
    name = request.params.get('name', None)
    category_id = request.matchdict.get('id', None)
    description = request.params.get('description', None)
    price = request.params.get('price', None)
    category = request.db.query(Category). \
        filter_by(id=category_id).first()
    categories = DBSession.query(Category). \
        filter_by(parent=None).all()

    if 'submit' in request.params:
        item = Item()
        item.name = name
        item.price = float(price)
        item.description = description
        item.category = category
        request.db.add(item)
        return HTTPFound(location=request.route_url('category', \
                                                    id=category_id))

    return {
        'title': 'Item Add',
        'categories': categories,
        'category': category,
    } 
開發者ID:Akagi201,項目名稱:learning-python,代碼行數:27,代碼來源:views.py

示例4: login_view

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def login_view(request):
    deform_static.need()

    search_path = ('myShop/templates/deform/',)
    renderer = deform.ZPTRendererFactory(search_path)
    schema = LoginFormSchema(validator=password_validator)
    form = deform.Form(schema, buttons=('submit',), renderer=renderer)

    if 'submit' in request.POST:
        try:
            appstruct = form.validate(request.POST.items())
        except deform.ValidationFailure, e:
            return {
                'title': 'login',
                'form': e.render()
            }

        user = appstruct['login']

        headers = remember(request, user.id)
        return HTTPFound(location='/', headers=headers) 
開發者ID:Akagi201,項目名稱:learning-python,代碼行數:23,代碼來源:views.py

示例5: __call__

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def __call__(self, context, request):
        lang = context['match']['lang']
        if lang not in self.val:
            # Redirect to default language
            raise HTTPFound(
                request.route_url(
                    context['route'].name,
                    **{
                        **context['match'],
                        "lang": request.registry.settings["default_locale_name"],
                    }
                )
            )

        request.response.set_cookie(
            "_LOCALE_", value=lang, max_age=20 * 7 * 24 * 60 * 60
        )
        request.locale_name = lang
        return True 
開發者ID:GFDRR,項目名稱:thinkhazard,代碼行數:21,代碼來源:__init__.py

示例6: get_redirect_query

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def get_redirect_query(request, expression=None, query_args=None):

    query_args = query_args or {}

    # FIXME: does not work due reverse proxy anomalies, tune it to make it work!
    #query = '{field}={value}'.format(**locals())
    #return HTTPFound(location=request.route_url('patentsearch', _query={'query': query}))

    # FIXME: this is a hack
    path = '/'
    host = request.headers.get('Host')

    # TODO: at least look this up in development.ini
    if 'localhost:6543' in host:
        path = ''

    redirect_url = path
    if expression:
        query_args.update({'query': expression})

    if query_args:
        redirect_url += '?' + urlencode(query_args)

    return HTTPFound(redirect_url) 
開發者ID:ip-tools,項目名稱:patzilla,代碼行數:26,代碼來源:views.py

示例7: redirect

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def redirect(self, to_url, permanent=False):
        if permanent:
            raise exc.HTTPMovedPermanently(to_url)
        raise exc.HTTPFound(to_url) 
開發者ID:mikeckennedy,項目名稱:python-for-entrepreneurs-course-demos,代碼行數:6,代碼來源:base_controller.py

示例8: index

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def index(request):
    vm = AccountHomeViewModel(request)
    if not vm.user:
        return x.HTTPFound('/account/login')

    return vm.to_dict()


# ################### REGISTER ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:11,代碼來源:account_controller.py

示例9: register_post

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def register_post(request: Request):
    vm = RegisterViewModel(request)
    vm.validate()

    if vm.error:
        return vm.to_dict()

    # create user
    user = user_service.create_user(vm.email, vm.name, vm.password)
    cookie_auth.set_auth(request, user.id)

    return x.HTTPFound('/account')


# ################### LOGIN ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:17,代碼來源:account_controller.py

示例10: login_post

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def login_post(request: Request):
    vm = LoginViewModel(request)
    vm.validate()

    if vm.error:
        return vm.to_dict()

    cookie_auth.set_auth(request, vm.user.id)
    return x.HTTPFound('/account')


# ################### LOGOUT ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:14,代碼來源:account_controller.py

示例11: logout

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def logout(request):
    cookie_auth.logout(request)
    return x.HTTPFound('/') 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:5,代碼來源:account_controller.py

示例12: index

# 需要導入模塊: from pyramid import httpexceptions [as 別名]
# 或者: from pyramid.httpexceptions import HTTPFound [as 別名]
def index(request):
    user_id = cookie_auth.get_user_id_via_auth_cookie(request)
    user = user_service.find_user_by_id(user_id)
    if not user:
        return x.HTTPFound('/account/login')

    return {
        'user': user,
        'user_id': user.id
    }


# ################### REGISTER ################################# 
開發者ID:talkpython,項目名稱:data-driven-web-apps-with-pyramid-and-sqlalchemy,代碼行數:15,代碼來源:account_controller.py


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