本文整理汇总了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,
}
示例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)
示例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
示例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)
示例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)
示例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