我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用pyramid.httpexceptions.HTTPMovedPermanently()。
def redirect(self, to_url, permanent=False): if permanent: raise exc.HTTPMovedPermanently(to_url) raise exc.HTTPFound(to_url)
def test_redirect(self): url = "https://example.com" result = response.redirect(url) self.assertIsInstance(result, HTTPMovedPermanently) self.assertEqual(result.location, url)
def submission_(request): username = request.matchdict.get('name') submitid = request.matchdict.get('submitid') form = request.web_input(submitid="", ignore="", anyway="") rating = define.get_rating(request.userid) submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid) extras = { "pdf": True, } if define.user_is_twitterbot(): extras['twitter_card'] = submission.twitter_card(submitid) try: item = submission.select_view( request.userid, submitid, rating, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: we.errorpage_kwargs = extras if 'twitter_card' in extras: extras['options'] = ['nocache'] if we.value in ("UserIgnored", "TagBlocked"): extras['links'] = [ ("View Submission", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise login = define.get_sysname(item['username']) canonical_path = request.route_path('submission_detail_profile', name=login, submitid=submitid, slug=slug_for(item['title'])) if request.GET.get('anyway'): canonical_path += '?anyway=true' if login != username: raise httpexceptions.HTTPMovedPermanently(location=canonical_path) extras["canonical_url"] = canonical_path extras["title"] = item["title"] page = define.common_page_start(request.userid, **extras) page.append(define.render('detail/submission.html', [ # Myself profile.select_myself(request.userid), # Submission detail item, # Subtypes macro.MACRO_SUBCAT_LIST, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000], ])) return Response(define.common_page_end(request.userid, page))