当前位置: 首页>>代码示例>>Python>>正文


Python http.HttpResponsePermanentRedirect方法代码示例

本文整理汇总了Python中django.http.HttpResponsePermanentRedirect方法的典型用法代码示例。如果您正苦于以下问题:Python http.HttpResponsePermanentRedirect方法的具体用法?Python http.HttpResponsePermanentRedirect怎么用?Python http.HttpResponsePermanentRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http的用法示例。


在下文中一共展示了http.HttpResponsePermanentRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_request

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def process_request(self, request):
        response = super().process_request(request)
        if response is not None:
            assert type(response) is http.HttpResponsePermanentRedirect
            patch_cache_control(response, public=True, max_age=settings.HTTPS_REDIRECT_CACHE_TIME)

            # Pull out just the HTTP headers from the rest of the request meta
            headers = {
                key.lstrip("HTTP_"): value
                for (key, value) in request.META.items()
                if key.startswith("HTTP_") or key == "CONTENT_TYPE" or key == "CONTENT_LENGTH"
            }

            logger.debug(
                f"Served HTTP to HTTPS redirect for {request.path}",
                extra={
                    "code": DEBUG_HTTP_TO_HTTPS_REDIRECT,
                    "method": request.method,
                    "body": request.body.decode("utf-8"),
                    "path": request.path,
                    "headers": headers,
                },
            )
        return response 
开发者ID:mozilla,项目名称:normandy,代码行数:26,代码来源:middleware.py

示例2: activate

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def activate(request, activation_key):
    context = {'info_title': _(u'oshibka')}
    user, user_info = AdmissionRegistrationProfile.objects.activate_user(activation_key)
    if user:
        if user_info:
            set_user_info(user, json.loads(user_info))

        contest_id = contest_register(user)
        if contest_id:
            return HttpResponsePermanentRedirect(settings.CONTEST_URL + 'contest/' + str(contest_id))
        else:
            context['info_text'] = _(u'oshibka_registracii_v_contest')
    else:
        context['info_text'] = _(u'nevernyy_kod_aktivatsii')

    return render(request, 'info_page.html', context) 
开发者ID:znick,项目名称:anytask,代码行数:18,代码来源:views.py

示例3: flatpage

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def flatpage(request, url):
    """
    Public interface to the flat page view.

    Models: `flatpages.flatpages`
    Templates: Uses the template defined by the ``template_name`` field,
        or :template:`flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `flatpages.flatpages` object
    """
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(FlatPage, url=url, sites=site_id)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(FlatPage, url=url, sites=site_id)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise
    return render_flatpage(request, f) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:views.py

示例4: detail

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def detail(request, slug, raw=False):

    slug = slug.strip('/')

    # handle redirects first
    try:
        redirect = Redirect.objects.get(old_slug=slug)      # noqa
        if redirect.status_code == 302:
            return HttpResponseRedirect(redirect.get_absolute_url())
        return HttpResponsePermanentRedirect(redirect.get_absolute_url())
    except Redirect.DoesNotExist:
        pass

    try:
        page = Page.objects.get(slug=slug)
    except Page.DoesNotExist:
        page = None
    if raw and page:
        return HttpResponse(page.raw, content_type='text/plain; charset=utf-8')
    elif raw:
        raise Http404

    context = {'page': page, 'slug': slug}
    return render(request, 'waliki/detail.html', context) 
开发者ID:mgaitan,项目名称:waliki,代码行数:26,代码来源:views.py

示例5: categories_show

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def categories_show(request, category_id, slug=None):
    category = get_object_or_404(
                   Category,
                   pk=category_id,
                   site_id=get_current_site(request).id
    )

    if slug is None:
        return HttpResponsePermanentRedirect(category.get_absolute_url())

    jobs = Job.objects.filter(site_id=get_current_site(request).id) \
                      .filter(category_id=category_id) \
                      .filter(paid_at__isnull=False) \
                      .filter(expired_at__isnull=True) \
                      .order_by('-paid_at')
    form = SubscribeForm()
    meta_desc = 'Browse a list of all active %s jobs' % category.name
    feed_url = reverse('categories_feed', args=(category.id, category.slug(),))
    title = '%s Jobs' % category.name
    context = {'meta_desc': meta_desc,
               'link_rss': feed_url,
               'title': title,
               'form': form,
               'jobs': jobs}
    return render(request, 'job_board/jobs_index.html', context) 
开发者ID:tramcar,项目名称:tramcar,代码行数:27,代码来源:categories.py

示例6: uploadFile

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def uploadFile(request):
    if request.method == 'POST':
        url = request.session.get("url")
        pwd = request.session.get("pwd")
        s = SendCode(url=url, pwd=pwd)
        newfile = request.FILES.get("newfile")
        now_filepath = request.session.get('now_path')
        path = now_filepath.split('/')[-1]
        filename = newfile.name
        filepath = now_filepath + "/" + filename
        content = ""
        for chunk in newfile.chunks():
            content = chunk.hex()
        res = s.uploadFile(filepath, content)
        return JsonResponse({"status": res, "path": path})
    else:
        return HttpResponsePermanentRedirect("/") 
开发者ID:imjdl,项目名称:WCnife,代码行数:19,代码来源:views.py

示例7: createFile

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def createFile(request):
    if request.method == 'POST':
        url = request.session.get("url")
        pwd = request.session.get("pwd")
        s = SendCode(url=url, pwd=pwd)
        now_filepath = request.session.get('now_path')
        path = now_filepath.split('/')[-1]
        filename = request.POST.get('filename')
        content = request.POST.get('content')
        if content is None:
            content = ''
        filepath = now_filepath + '/' + filename
        res = s.createFile(filepath, content)
        return JsonResponse({"status": res, "path": path})
    else:
        return HttpResponsePermanentRedirect("/") 
开发者ID:imjdl,项目名称:WCnife,代码行数:18,代码来源:views.py

示例8: post

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def post(self, request):
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            user_name = request.POST.get("username", "")
            pass_word = request.POST.get("password", "")
            user = authenticate(username=user_name, password=pass_word)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponsePermanentRedirect(reverse('index'))
                else:
                    return render(request, "user_login.html", {"msg": "邮箱未激活"})
            else:
                return render(request, "user_login.html", {"msg": "用户名或密码错误"})
        else:
            return render(request, "user_login.html", {"login_form": login_form}) 
开发者ID:abaoMAO,项目名称:django_OA,代码行数:18,代码来源:views.py

示例9: dispatch

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def dispatch(self, request, *args, **kwargs):
        slug = self.kwargs['slug']

        try:
            bill = self.model.objects.get(slug=slug)
            response = super().dispatch(request, *args, **kwargs)
        except NYCBill.DoesNotExist:
            bill = None

        if bill is None:
            try:
                bill = self.model.objects.get(slug__startswith=slug)
                response = HttpResponsePermanentRedirect(reverse('bill_detail', args=[bill.slug]))
            except NYCBill.DoesNotExist:
                try: 
                    one, two, three, four = slug.split('-')
                    short_slug = slug.replace('-' + four, '')
                    bill = self.model.objects.get(slug__startswith=short_slug)
                    response = HttpResponsePermanentRedirect(reverse('bill_detail', args=[bill.slug]))
                except:
                    response = HttpResponseNotFound()

        return response 
开发者ID:datamade,项目名称:nyc-councilmatic,代码行数:25,代码来源:views.py

示例10: redirect_middleware

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def redirect_middleware(get_response):
    def middleware(request):
        path = request.path.lstrip('/')
        redirects = list(Redirect.objects.filter(
            domain=request.get_host(),
            # We redirect on either a path match or a '*'
            # record existing for this domain
            path__in=(path, '*')
        ))
        # A non-star redirect always takes precedence
        non_star = [r for r in redirects if r.path != '*']
        if non_star:
            return HttpResponsePermanentRedirect(non_star[0].target)
        # If there's a star redirect, build path and redirect to that
        star = [r for r in redirects if r.path == '*']
        if star:
            new_url = star[0].target + path
            if request.META['QUERY_STRING']:
                new_url += '?' + request.META['QUERY_STRING']
            return HttpResponsePermanentRedirect(new_url)
        # Default: no redirects, just get on with it:
        return get_response(request)

    return middleware 
开发者ID:simonw,项目名称:simonwillisonblog,代码行数:26,代码来源:middleware.py

示例11: serve_protected_file

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def serve_protected_file(request, persona, pk):
    """
    Restituisce il file e incrementa il numero di downloads
    """
    try:
        file_obj = File.objects.get(pk=int(pk))
        file_obj.incrementa_downloads()
    except File.DoesNotExist:
        raise Http404('File not found')
    if file_obj.url_documento:
        return HttpResponsePermanentRedirect(file_obj.url_documento)
    if not file_obj.has_read_permission(request):
        if settings.DEBUG:
            raise PermissionDenied
        else:
            raise Http404('File not found')
    return server.serve(request, file_obj=file_obj.file, save_as=True) 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:19,代码来源:viste.py

示例12: no_querystring

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def no_querystring(view_func):
    def decorator(request, *args, **kwargs):
        if request.GET:
            return HttpResponsePermanentRedirect(request.path)
        return view_func(request, *args, **kwargs)

    return decorator 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:9,代码来源:decorators.py

示例13: student_info

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def student_info(request, userid=None):
    # old student search view: new search is better in every way.
    messages.add_message(request, messages.INFO, 'The old student search has been replaced with an awesome site search, accessible from the search box at the top of every page in %s.' % (product_name(request),))
    return HttpResponsePermanentRedirect(reverse('dashboard:site_search'))


# documentation views 
开发者ID:sfu-fas,项目名称:coursys,代码行数:9,代码来源:views.py

示例14: get

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning('Gone: %s', request.path,
                        extra={
                            'status_code': 410,
                            'request': request
                        })
            return http.HttpResponseGone() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:16,代码来源:base.py

示例15: process_request

# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponsePermanentRedirect [as 别名]
def process_request(self, request):
        path = request.path.lstrip("/")
        if (self.redirect and not request.is_secure() and
                not any(pattern.search(path)
                        for pattern in self.redirect_exempt)):
            host = self.redirect_host or request.get_host()
            return HttpResponsePermanentRedirect(
                "https://%s%s" % (host, request.get_full_path())
            ) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:security.py


注:本文中的django.http.HttpResponsePermanentRedirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。