本文整理汇总了Python中werkzeug.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: application
def application(request):
try:
adapter = predefined_urls.bind_to_environ(request.environ)
endpoint, values = adapter.match()
return handle_request(endpoint, request, **values)
except NotFound:
redir = find_redirect(request.path)
if redir:
return redirect(redir.new_path, code=redir.code)
#print "Request path: " + request.path
if request.path[-1] == '/':
request_path = request.path.rstrip('/');
return redirect(request_path, code=301)
url_map = find_url_map(request.path)
if url_map:
return handle_request('pages.main', request, url_map)
# Log this request in the 404 log and display not found page
if request.path not in [ "/wp-login.php", "/apple-touch-icon-precomposed.png", "/plus/mytag_js.php", "/apple-touch-icon-120x120-precomposed.png", "/apple-touch-icon-120x120.png", "/blog/wp-json/wp/v2/posts", "/blog/wp-json/wp/v2/users", "/ads.txt", "/plus/ad_js.php", "/apple-touch-icon-152x152-precomposed.png", "/apple-touch-icon-152x152.png", "/xmlrpc.php", "/utility/convert/data/config.inc.php", "/plus/download.php", "/config/AspCms_Config.asp", "/plus/mytag_j.php", "/plus/moon.php", "/data/img/css/xianf.ASP", "/bbs/utility/convert/data/config.inc.php", "/plus/bakup.hp", "/dxyylc/md5.aspx", "/plus/90sec.php", "/plus/laobiao.php", "/plus/e7xue.php", "/_s_/dyn/SessionState_ping", "/phpmyadmin", "/dxyylc/md5.php", "/browserconfig.xml", "/include/ckeditor/plugins/pagebreak/images/inCahe.php", "/include/code/mp.php", "/plus/mybak.php", "/install/m7lrv.php", "/weki.php", "/wordpress", "/wp", "/include/helperss/filter.helpear.php", "/templets/plus/sky.php", "/install/modurnlecscache.php", "/plus/xsvip.php", "/plus/myjs.php", "/include/data/fonts/uddatasql.php", "/plus/bakup.php", "/plus/av.php", "/data/cache/asd.php", "/lang/cn/system.php", "/data/data/index.php", "/sitemap/templates/met/SqlIn.asp", "/utility/convert/include/rom2823.php", "/xiaolei.php", "/data/conn/config.php", "/plus/mycak.php", "/plus/x.php", "/search.php", "/weki.asp", "/install/md5.php", "/Somnus/Somnus.asp", "/md5.asp", "/plus/read.php", "/plus/backup.php", "/plus/service.php", "/plus/spider.php", "/book/story_dod_hjkdsafon.php", "/plus/zdqd.php", "/data/s.asp", "/plus/90000.php" ]:
log_404(request)
return handle_request('not_found.main', request)
except:
log_exception(request)
return handle_request('exception.main', request)
finally:
session.remove()
开发者ID:pkrumins,项目名称:catonmat.net,代码行数:28,代码来源:application.py
示例2: add
def add(request, key=None, type=FILE):
to = key # lame but it does the trick for now
if type == FOLDER:
form = FolderForm(request.form)
else:
form = FileForm(request.form)
if request.method == "POST" and form.validate():
if len(form.slug.data) < 1:
form.slug.data = slugify(form.name.data)
if type == FOLDER:
file = File.add(to=to,type=type, name=form.name.data,
slug=form.slug.data,
breadcrumb=form.breadcrumb.data,
state=form.state.data,
active=form.active.data,
author=users.get_current_user(),
updated=datetime.now())
elif type == FILE:
file = request.files.get('file')
data = db.Blob(file.read())
file = File.add(to=to,type=type, name=form.name.data,
slug=form.slug.data,
breadcrumb=form.breadcrumb.data,
state=form.state.data,
active=form.active.data,
author=users.get_current_user(),
updated=datetime.now(),
content_type=file.content_type,
data=data, size=len(data))
if form.save.data is True:
return redirect(url_for('nut:files/list'), 301)
if form.cont.data is True:
return redirect(url_for('nut:files/edit', key=file.key()), 301)
return render_template('app:files/form.html', form=form)
开发者ID:4416,项目名称:hazel-cms,代码行数:35,代码来源:views.py
示例3: passwort_aendern
def passwort_aendern(request):
if request.method != 'POST':
return redirect('/helfer')
old_pw = request.form.get('old_pw')
new_first = request.form.get('new_first')
new_second = request.form.get('new_second')
if not check_login_credentials(request.session['username'], old_pw):
error_long = u"Das alte Passwort, das du eingegeben hast, stimmt nicht. Du kannst dein Passwort auch bei einem Admin ändern lassen, frag am besten per Mail bei %s" % config.admin_email
return render_template('error.xml', error_short=u"altes passwort falsch",
error_long=error_long,
session=request.session)
if new_first != new_second:
error_long = u"Die beiden neuen Passwörter sind nicht gleich. Du hast dich sehr wahrscheinlich vertippt. Du kannst dein Passwort auch bei einem Admin ändern lassen, frag am besten per Mail bei %s" % config.admin_email
return render_template('error.xml',
error_short=u"Neue Passwörter sind unterschiedlich",
error_long=error_long,
session=request.session)
crypted = sha256_crypt.encrypt(new_first)
db.update('UPDATE person SET password=? WHERE id=?', (crypted,
request.session['userid']))
return redirect('/redirect/my_page')
开发者ID:t-animal,项目名称:helfertool,代码行数:26,代码来源:helfer.py
示例4: verify_email
def verify_email(self, sign, max_age=24 * 60 * 60):
"""
Verifies the email and redirects to home page. This is a method in
addition to the activate method which activates the account in addition
to verifying the email.
"""
try:
unsigned = self._serializer.loads(
self._signer.unsign(sign, max_age=max_age),
salt='verification'
)
except SignatureExpired:
return self.build_response(
'The verification link has expired',
redirect(url_for('nereid.website.home')), 400
)
except BadSignature:
return self.build_response(
'The verification token is invalid!',
redirect(url_for('nereid.website.home')), 400
)
else:
if self.id == unsigned:
self.email_verified = True
self.save()
return self.build_response(
'Your email has been verified!',
redirect(url_for('nereid.website.home')), 200
)
else:
return self.build_response(
'The verification token is invalid!',
redirect(url_for('nereid.website.home')), 400
)
开发者ID:2cadz,项目名称:nereid,代码行数:34,代码来源:user.py
示例5: login_box
def login_box(request):
from kay.auth import login
next = unquote_plus(request.values.get("next"))
owned_domain_hack = request.values.get("owned_domain_hack")
message = ""
form = LoginBoxForm()
if request.method == "POST":
if form.validate(request.form):
result = login(request, user_name=form.data['user_name'],
password=form.data['password'])
if result:
if owned_domain_hack == 'True':
original_host_url = unquote_plus(
request.values.get("original_host_url"))
url = original_host_url[:-1] + url_for("auth/post_session")
url += '?' + url_encode({'session_id': result.key().name(),
'next': next})
return redirect(url)
else:
return redirect(next)
else:
message = _("Failed to login.")
return render_to_response("auth/loginform.html",
{"form": form.as_widget(),
"message": message})
开发者ID:tukutela,项目名称:Kay-Framework,代码行数:26,代码来源:views.py
示例6: post
def post(self, slug):
if self.request.user.is_anonymous() or not self.request.user.is_admin:
return Unauthorized()
page = SPage.get_by_key_name(slug)
if page:
form = SPageForm(page)
else:
form = SPageForm()
if form.validate(self.request.form):
try:
SPage(
key_name=slug,
title=form["title"],
meta_desc=form["meta_desc"],
body=form["body"],
body_html=markdown2html(form["body"]),
).put()
self.request.notifications.success("Strona zapisana!")
return redirect(self.request.base_url)
except Exception, e:
logging.exception("Static page save failed: " + str(e))
self.request.notifications.error("Zmian nie zapisano! Błąd zapisu.")
return redirect(self.request.base_url)
开发者ID:gluwer,项目名称:przepisymm,代码行数:26,代码来源:views.py
示例7: dinge_aendern
def dinge_aendern(request):
if request.method != 'POST':
return redirect('/helfer')
userid = request.session['userid']
new_email = request.form.get('email')
new_mobile = request.form.get('mobile')
want_shirt = request.form.get('want_participant_shirt') == "on"
old_want_shirt = db.select('SELECT want_participant_shirt FROM person WHERE id=?', (userid,))
if len(old_want_shirt) != 1:
## this should never happen, if the @require_login works as expected
## (i.e. if you ever trigger this assertion, go fix @require_login)
assert False
old_want_shirt= old_want_shirt[0]['want_participant_shirt']
## XXX: this feels redundant, but also sql-injection-exploitable if
## shortened too much..
if config.shirt_stuff_changeable:
db.update('''UPDATE
person
SET
email=?,mobile=?,want_participant_shirt=?
WHERE
id=?''', (new_email, new_mobile, want_shirt, userid))
else:
db.update('''UPDATE
person
SET
email=?,mobile=?
WHERE
id=?''', (new_email, new_mobile, userid))
return redirect('/helfer/%d' % (userid,))
开发者ID:t-animal,项目名称:helfertool,代码行数:35,代码来源:helfer.py
示例8: topic
def topic(request, id, slug=None):
"""Shows a topic."""
topic = Topic.query.eagerposts().get(id)
# if the topic id does not exist or the topic is from a different
# language, we abort with 404 early
if topic is None or topic.locale != request.view_lang:
raise NotFound()
# make sure the slug is okay, otherwise redirect to the real one
# to ensure URLs are unique.
if slug is None or topic.slug != slug:
return redirect(url_for(topic))
# deleted posts cannot be seen by people without privilegs
if topic.is_deleted and not (request.user and request.user.is_moderator):
raise Forbidden()
# a form for the replies.
form = ReplyForm(topic)
if request.method == 'POST' and form.validate():
reply = form.create_reply()
session.commit()
request.flash(_(u'Your reply was posted.'))
return redirect(url_for(reply))
# pull in the votes in a single query for all the posts related to the
# topic so that we only have to fire the database once.
if request.is_logged_in:
request.user.pull_votes(topic.posts)
return render_template('kb/topic.html', topic=topic,
reply_form=form.as_widget())
开发者ID:Plurk,项目名称:Solace,代码行数:34,代码来源:kb.py
示例9: add_to_cart
def add_to_cart(cls):
"""
Adds the given item to the cart if it exists or to a new cart
The form is expected to have the following data is post
quantity : decimal
product : integer ID
action : set (default), add
Response:
'OK' if X-HTTPRequest
Redirect to shopping cart if normal request
"""
form = AddtoCartForm()
if form.validate_on_submit():
cart = cls.open_cart(create_order=True)
action = request.values.get('action', 'set')
if form.quantity.data <= 0:
flash(
_('Be sensible! You can only add real quantities to cart')
)
return redirect(url_for('nereid.cart.view_cart'))
cart._add_or_update(
form.product.data, form.quantity.data, action
)
if action == 'add':
flash(_('The product has been added to your cart'), 'info')
else:
flash(_('Your cart has been updated with the product'), 'info')
if request.is_xhr:
return jsonify(message='OK')
return redirect(url_for('nereid.cart.view_cart'))
开发者ID:aroraumang,项目名称:nereid-cart-b2c,代码行数:34,代码来源:cart.py
示例10: add
def add(cls):
"""
Adds a contact mechanism to the party's contact mechanisms
"""
form = cls.get_form()
if form.validate_on_submit():
cls.create(
[
{
"party": request.nereid_user.party.id,
"type": form.type.data,
"value": form.value.data,
"comment": form.comment.data,
}
]
)
if request.is_xhr:
return jsonify({"success": True})
return redirect(request.referrer)
if request.is_xhr:
return jsonify({"success": False})
else:
for field, messages in form.errors:
flash("<br>".join(messages), "Field %s" % field)
return redirect(request.referrer)
开发者ID:GauravButola,项目名称:nereid,代码行数:26,代码来源:party.py
示例11: application
def application(request):
try:
adapter = predefined_urls.bind_to_environ(request.environ)
endpoint, values = adapter.match()
return handle_request(endpoint, request, **values)
except NotFound:
redir = find_redirect(request.path)
if redir:
return redirect(redir.new_path, code=redir.code)
#print "Request path: " + request.path
if request.path[-1] != '/':
return redirect(request.path + '/', code=301)
url_map = find_url_map(request.path)
if url_map:
return handle_request('pages.main', request, url_map)
# Log this request in the 404 log and display not found page
log_404(request)
return handle_request('not_found.main', request)
except:
log_exception(request)
return handle_request('exception.main', request)
finally:
session.remove()
开发者ID:gobburms,项目名称:catonmat.net,代码行数:26,代码来源:application.py
示例12: add_to_cart
def add_to_cart(cls):
"""
Adds the given item to the cart if it exists or to a new cart
The form is expected to have the following data is post
quantity : decimal
product : integer ID
action : set (default), add
Response:
'OK' if X-HTTPRequest
Redirect to shopping cart if normal request
"""
form = AddtoCartForm(request.form)
if request.method == "POST" and form.validate():
cart = cls.open_cart(create_order=True)
action = request.values.get("action", "set")
if form.quantity.data <= 0:
flash(_("Be sensible! You can only add real quantities to cart"))
return redirect(url_for("nereid.cart.view_cart"))
cls._add_or_update(cart.sale.id, form.product.data, form.quantity.data, action)
if action == "add":
flash(_("The product has been added to your cart"), "info")
else:
flash(_("Your cart has been updated with the product"), "info")
if request.is_xhr:
return jsonify(message="OK")
return redirect(url_for("nereid.cart.view_cart"))
开发者ID:shalabhaggarwal,项目名称:nereid-cart-b2c,代码行数:30,代码来源:cart.py
示例13: login
def login(request):
from kay.auth import login
if settings.AUTH_POST_LOGIN_SUCCESS_DEFAULT_URL:
next = unquote_plus(request.values.get("next", settings.AUTH_POST_LOGIN_SUCCESS_DEFAULT_URL))
else:
next = unquote_plus(request.values.get("next", "/"))
owned_domain_hack = request.values.get("owned_domain_hack")
message = ""
form = LoginForm()
if request.method == "POST":
if form.validate(request.form):
result = login(request, user_name=form.data['user_name'],
password=form.data['password'])
if result:
if owned_domain_hack == 'True':
original_host_url = unquote_plus(
request.values.get("original_host_url"))
url = original_host_url[:-1] + url_for("auth/post_session")
url += '?' + url_encode({'session_id': result.key().name(),
'next': next})
return redirect(url)
else:
return redirect(next)
else:
message = _("Failed to login successfully with those credentials, try another or click the 'Forgot Password' link below.")
return render_to_response("auth/loginform.html",
{"form": form.as_widget(),
"message": message})
开发者ID:tukutela,项目名称:Kay-Framework,代码行数:29,代码来源:views.py
示例14: vote
def vote(request, post):
"""Votes on a post."""
# TODO: this is currently also fired as GET if JavaScript is
# not available. Not very nice.
post = Post.query.get(post)
if post is None:
raise NotFound()
# you cannot cast votes on deleted shit
if post.is_deleted:
message = _(u"You cannot vote on deleted posts.")
if request.is_xhr:
return json_response(message=message, error=True)
request.flash(message, error=True)
return redirect(url_for(post))
# otherwise
val = request.args.get("val", 0, type=int)
if val == 0:
request.user.unvote(post)
elif val == 1:
# users cannot upvote on their own stuff
if post.author == request.user:
message = _(u"You cannot upvote your own post.")
if request.is_xhr:
return json_response(message=message, error=True)
request.flash(message, error=True)
return redirect(url_for(post))
# also some reputation is needed
if not request.user.is_admin and request.user.reputation < settings.REPUTATION_MAP["UPVOTE"]:
message = _(u"In order to upvote you " u"need at least %d reputation") % settings.REPUTATION_MAP["UPVOTE"]
if request.is_xhr:
return json_response(message=message, error=True)
request.flash(message, error=True)
return redirect(url_for(post))
request.user.upvote(post)
elif val == -1:
# users need some reputation to downvote. Keep in mind that
# you *can* downvote yourself.
if not request.user.is_admin and request.user.reputation < settings.REPUTATION_MAP["DOWNVOTE"]:
message = (
_(u"In order to downvote you " u"need at least %d reputation") % settings.REPUTATION_MAP["DOWNVOTE"]
)
if request.is_xhr:
return json_response(message=message, error=True)
request.flash(message, error=True)
return redirect(url_for(post))
request.user.downvote(post)
else:
raise BadRequest()
session.commit()
# standard requests are answered with a redirect back
if not request.is_xhr:
return redirect(url_for(post))
# others get a re-rendered vote box
box = get_macro("kb/_boxes.html", "render_vote_box")
return json_response(html=box(post, request.user))
开发者ID:jlsandell,项目名称:solace,代码行数:59,代码来源:kb.py
示例15: do_logout
def do_logout():
if request.user.anon:
flash(u'Du warst nicht eingeloggt', False)
return redirect(request.args.get("next",None) or url_for("pybble.views.mainpage"))
else:
logged_out()
flash(u'Du hast dich erfolgreich abgemeldet.', True)
return redirect(url_for("pybble.views.mainpage"))
开发者ID:smurfix,项目名称:pybble,代码行数:8,代码来源:login.py
示例16: order
def order(request, order_key):
order_obj = Order.get(order_key)
if not order_obj:
redirect(url_for('admin/orders_lists'))
gifts = []
for gift in order_obj.items:
gifts.append(OrderItem.get(gift))
return render_to_response('admin/order.html', {'order':order_obj, 'gifts':gifts})
开发者ID:gmist,项目名称:five-studio,代码行数:8,代码来源:views.py
示例17: redirector
def redirector(request):
if request.form.get('helfer_id'):
return redirect('/helfer/' + request.form.get('helfer_id'))
elif request.form.get('schicht_id'):
return redirect('/schicht/' + request.form.get('schicht_id'))
elif request.form.get('station_id'):
return redirect('/station/' + request.form.get('station_id'))
else:
return redirect('/')
开发者ID:t-animal,项目名称:helfertool,代码行数:9,代码来源:views.py
示例18: get_quickmark
def get_quickmark(request, quickmark):
print "quickmark=[" + quickmark +"]"
if quickmark == '':
return redirect('/static/browse.html')
bm = tuple(app.db.get_bookmarks(quickmark = quickmark))
if not len(bm):
raise NotFound
return redirect(bm[0]['url'])
开发者ID:Droggelbecher,项目名称:0lz,代码行数:9,代码来源:controllers.py
示例19: add_to_cart
def add_to_cart(cls):
"""
Adds the given item to the cart if it exists or to a new cart
The form is expected to have the following data is post
quantity : decimal
product : integer ID
action : set (default), add
Response:
'OK' if X-HTTPRequest
Redirect to shopping cart if normal request
"""
Product = Pool().get('product.product')
form = AddtoCartForm()
if form.validate_on_submit():
cart = cls.open_cart(create_order=True)
action = request.values.get('action', 'set')
if form.quantity.data <= 0:
message = _(
'Be sensible! You can only add real quantities to cart')
if request.is_xhr:
return jsonify(message=unicode(message)), 400
flash(message)
return redirect(url_for('nereid.cart.view_cart'))
if not Product(form.product.data).template.salable:
message = _("This product is not for sale")
if request.is_xhr:
return jsonify(message=unicode(message)), 400
flash(message)
return redirect(request.referrer)
sale_line = cart.sale._add_or_update(
form.product.data, form.quantity.data, action
)
# Validate that product availability in inventory is not less than
# warehouse quantity
sale_line.validate_for_product_inventory()
sale_line.save()
if action == 'add':
message = _('The product has been added to your cart')
else:
message = _('Your cart has been updated with the product')
if request.is_xhr:
return jsonify(
message=unicode(message),
line=sale_line.serialize(purpose='cart')
), 200
flash(message, 'info')
return redirect(url_for('nereid.cart.view_cart'))
开发者ID:2cadz,项目名称:nereid-cart-b2c,代码行数:57,代码来源:cart.py
示例20: index
def index():
if user.is_authed():
return redirect(url_for("user_frontpage"))
if institution.is_authed():
return redirect(url_for("institution_frontpage"))
if admin.is_authed():
return Response("admin")
response = Response()
template_response("/pages/frontpage.mako", response)
return response
开发者ID:bjornua,项目名称:fprojekt2010,代码行数:10,代码来源:responders.py
注:本文中的werkzeug.redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论