Python django.shortcuts 模块,Http404() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用django.shortcuts.Http404()

项目:directory-ui-buyer    作者:uktrade    | 项目源码 | 文件源码
def dispatch(self, *args, **kwargs):
        if not settings.EXPOSE_DIRECTORY_API:
            raise Http404()
        return super().dispatch(*args, **kwargs)
项目:directory-ui-buyer    作者:uktrade    | 项目源码 | 文件源码
def dispatch(self, *args, **kwargs):
        if not self.flag:
            raise Http404()
        return super().dispatch(*args, **kwargs)
项目:directory-ui-buyer    作者:uktrade    | 项目源码 | 文件源码
def get_form_initial(self, step):
        if not self.kwargs['id']:
            return {}
        response = api_client.company.retrieve_private_case_study(
            sso_session_id=self.request.sso_user.session_id,
            case_study_id=self.kwargs['id'],
        )
        if response.status_code == 404:
            raise Http404()
        response.raise_for_status()
        return response.json()
项目:directory-ui-supplier    作者:uktrade    | 项目源码 | 文件源码
def dispatch(self, request, *args, **kwargs):
        # handling legacy "show summary/verbose description" url: ED-1471
        if 'verbose' in self.request.GET:
            return redirect('sector-detail-verbose', slug=self.kwargs['slug'])
        if self.kwargs['slug'] not in self.get_active_pages():
            raise Http404()
        return super().dispatch(request, *args, **kwargs)
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def admin_network_form(request):
    """
    Ajax page for updating, removing and adding networks.
    """
    qs = request.GET.copy()

    if request.POST['action'] == 'update':
        try:
            net = Subnet.objects.select_related('owner', 'dc_bound').get(name=request.POST['adm-name'])
        except Subnet.DoesNotExist:
            raise Http404
    else:
        net = None

    form = AdminNetworkForm(request, net, request.POST, prefix='adm')

    if form.is_valid():
        args = (form.cleaned_data['name'],)
        status = form.save(args=args)

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            if form.action == 'create' and not form.cleaned_data.get('dc_bound'):
                qs['all'] = 1  # Show all items if adding new item and not attaching

            # Redirect to ip list or network list depending on ips parameter
            if request.GET.get('ips', False):
                redir_view = 'dc_network_ip_list'
                redir_args = (net.name,)
            else:
                redir_view = 'dc_network_list'
                redir_args = ()

            return redirect(redir_view, *redir_args, query_string=qs)

    return render(request, 'gui/dc/network_admin_form.html', {'form': form, 'nodc': request.GET.get('ips', '')})
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def network_ip_form(request, name):
    """
    Ajax page for updating, removing and adding network IP address(es).
    """
    try:
        net = Subnet.objects.get(name=name)
    except Subnet.DoesNotExist:
        raise Http404

    form_class = NetworkIPForm

    if request.POST['action'] == 'update':
        try:
            ip = IPAddress.objects.get(subnet=net, ip=request.POST.get('ip'))
        except IPAddress.DoesNotExist:
            raise Http404
    else:
        ip = None
        if request.POST.get('ips', False):
            form_class = MultiNetworkIPForm

    form = form_class(request, net, ip, request.POST)

    if form.is_valid():
        status = form.save(args=form.api_call_args(name))

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            messages.success(request, form.get_action_message())
            return redirect('dc_network_ip_list', net.name, query_string=request.GET)

    return render(request, form.template, {'form': form, 'net': {'name': name}})
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def dc_subnet_ip_list(request, network, netmask, vlan_id):
    context = collect_view_data(request, 'dc_network_list')
    context['is_staff'] = request.user.is_staff

    try:
        context['ip_network'] = ip_network = Subnet.get_ip_network(network, netmask)  # Invalid IPv4 network
        context['vlan_id'] = int(vlan_id)
    except ValueError:
        raise Http404

    network, netmask = ip_network.with_netmask.split('/')
    context['netinfo'] = Subnet.get_ip_network_hostinfo(ip_network)
    nets = Subnet.objects.filter(network=network, netmask=netmask, vlan_id=vlan_id)
    context['num_networks'] = num_networks = nets.count()

    if not num_networks:
        raise Http404  # Invalid user input - made-up IPv4network

    context['order_by'], order_by = get_order_by(request, api_view=NetworkIPPlanView)
    ips = IPAddress.objects.select_related('vm', 'vm__dc', 'subnet')\
                           .prefetch_related('vms')\
                           .filter(subnet__in=nets)\
                           .order_by(*order_by).distinct()
    context['ips'] = context['pager'] = pager = get_pager(request, ips, per_page=50)
    context['total'] = pager.paginator.count
    context['free'] = ips.filter(usage=IPAddress.VM, vm__isnull=True, vms=None).count()

    return render(request, 'gui/dc/subnet_ip_list.html', context)
项目:covart-web    作者:cyliang    | 项目源码 | 文件源码
def dispatch(self, request, *args, **kwargs):
        self.asset = self.get_asset()
        if self.asset.latest_log.status == models.TransferLog.SCRAP:
            raise Http404('This is not a mutable asset.')

        return super(AssetLoggingMixin, self).dispatch(request, *args, **kwargs)
项目:sec-scan-agent_v1.0    作者:Canbing007    | 项目源码 | 文件源码
def register(request):
    obj_R = RegisterForm()
    retR = {'dataR':None,'errorR':''}
    retR['dataR'] = obj_R
    if request.method == 'POST':
        checkform = RegisterForm(request.POST)
        checkresult = checkform.is_valid()
        if checkresult:
            Addr = request.META['REMOTE_ADDR']
            Agent = request.META['HTTP_USER_AGENT']
            Register_date = str(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))

            #print request.POST
            Username = request.POST.get('username','')
            Password = request.POST.get('password','')
            Email = request.POST.get('email','')
            Phone = request.POST.get('phone','')

            G = models.UserGroup.objects.get(gname="user")
            key = 48
            result = models.UserInfo.objects.create(username = Username,password = encrypt(key, Password),email = Email,phone = Phone,ip = Addr,agent = Agent,register_date = Register_date,permiss = G )
            if result:
                return HttpResponseRedirect('/')
            else:
                raise Http404("Register is fail")
        else:
            errorMsg = checkform.errors
            firstErrorMsg = checkform.errors.as_data().values()[0][0].messages[0]
            retR['errorR'] = firstErrorMsg
    return render_to_response('user/register_index.html', retR)
项目:eoj3    作者:ultmaster    | 项目源码 | 文件源码
def get_queryset(self):
        try:
            queryset = self.get_selected_from().select_related('problem', 'author').\
                only('pk', 'contest_id', 'create_time', 'author_id', 'author__username', 'author__nickname',
                     'author__magic', 'problem_id', 'problem__title', 'lang', 'status', 'status_time', 'status_percent',
                     'code_length', 'ip', 'cheat_tag')
            if not self.privileged and not self.contest_submission_visible and not is_admin_or_root(self.request.user):
                queryset = queryset.filter(contest__isnull=True, problem__visible=True)

            if 'user' in self.request.GET:
                queryset = queryset.filter(author_id=self.request.GET['user'])
            if self.allow_problem_query and 'problem' in self.request.GET:
                queryset = queryset.filter(problem_id=self.reinterpret_problem_identifier(self.request.GET['problem']))
            if 'lang' in self.request.GET:
                queryset = queryset.filter(lang=self.request.GET['lang'])
            if self.allow_verdict_query and 'verdict' in self.request.GET:
                queryset = queryset.filter(status=int(self.request.GET['verdict'][1:]))

            if self.distinct_by_author:
                author_set = set()
                res = []
                for submission in queryset.all():
                    if submission.author_id not in author_set:
                        author_set.add(submission.author_id)
                        res.append(submission)
                        if self.query_number and len(res) >= self.query_number:
                            break
                return res
            else:
                return queryset.all()[:self.query_number]
        except Exception as e:
            raise Http404(e)
项目:sec-scan-agent_v1.0    作者:Canbing007    | 项目源码 | 文件源码
def login(request):
    auth_user = request.COOKIES.get('user_auths','')
    if auth_user != '':
        return HttpResponseRedirect("/index/")
    obj_L = LoginForm()
    retL = {'dataL':None,'errorL':''}
    retL['dataL'] = obj_L
    if request.method == 'POST':
        checkform = LoginForm(request.POST)
        checkresult = checkform.is_valid()
        if checkresult:
            key = 48
            loginip = request.META['REMOTE_ADDR']
            loginagent = request.META['HTTP_USER_AGENT']
            logindate = str(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
            Username = request.POST.get('username','')
            Password = request.POST.get('password','')
            user = models.UserInfo.objects.filter(username__exact=Username,password__exact=encrypt(key, Password))
            if user:
                U = models.UserInfo.objects.filter(username=Username)
                for item in U:
                    value = item.password
                #????????
                #result = models.UserLogin(login_date = login_date,login_ip = Login_ip,login_agent = Login_agent,login_name = U)
                #result.save()
                T = models.UserInfo.objects.get(username=Username)
                models.UserLogin.objects.create(login_name=T,login_agent=loginagent,login_ip=loginip,login_date=logindate)
                user_hashs = user_auth(value)
                response = HttpResponseRedirect("/index/")
                response.set_cookie('user_name',Username,3600)
                response.set_cookie('user_auths',user_hashs,3600,None,path='/',domain=None,secure=None,httponly=True)
                models.UserInfo.objects.update(user_hash=user_hashs)
                return response
            else:
                #raise Http404("make set cookie fail")
                return HttpResponseRedirect("/")
        else:
            errorMsg = checkform.errors
            firstErrorMsg = checkform.errors.as_data().values()[0][0].messages[0]
            retL['errorL'] = firstErrorMsg
            #return HttpResponseRedirect("/register/")

    return render_to_response('user/login_index.html', retL)