Python django.shortcuts.Http404() Examples

The following are 8 code examples for showing how to use django.shortcuts.Http404(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.shortcuts , or try the search function .

Example 1
Project: canvas   Author: canvasnetworks   File:    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def user_profile(username):
    user = get_object_or_404(User.objects.select_related('userinfo', 'userinfo__avatar'), username=username)

    if not user.is_active:
        raise Http404("Deactivated user.")

    follow_counts = following_models.counts(user)

    return {
        'user': user.details(),
        'bio': user.userinfo.bio_text,
        'quest_completion_count': Quest.completed_by_user_count(user),
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],

# Cache invalidation for user_profile. 
Example 2
Project: django-pyas2   Author: abhishek-ram   File:    License: GNU General Public License v3.0 5 votes vote down vote up
def get(self, request, obj_type, obj_id, *args, **kwargs):
        filename = ""
        file_content = ""
        # Get the file content based
        if obj_type == "message_payload":
            obj = get_object_or_404(Message, pk=obj_id)
            filename = os.path.basename(
            file_content =

        elif obj_type == "mdn_payload":
            obj = get_object_or_404(Mdn, pk=obj_id)
            filename = os.path.basename(
            file_content =

        elif obj_type == "public_cert":
            obj = get_object_or_404(PublicCertificate, pk=obj_id)
            filename =
            file_content = obj.certificate

        elif obj_type == "private_key":
            obj = get_object_or_404(PrivateKey, pk=obj_id)
            filename =
            file_content = obj.key

        # Return the file contents as attachment
        if filename and file_content:
            response = HttpResponse(content_type="application/x-pem-file")
            disposition_type = "attachment"
            response["Content-Disposition"] = (
                disposition_type + "; filename=" + filename
            return response
            raise Http404() 
Example 3
Project: junction   Author: pythonindia   File:    License: MIT License 5 votes vote down vote up
def non_proposal_schedule_item_view(request, sch_item_id):
        sch_item = ScheduleItem.objects.get(pk=sch_item_id)
        return render(
            request, "proposals/detail/schedule-item.html", {"sch_item": sch_item}
    except ObjectDoesNotExist:
        raise Http404() 
Example 4
Project: esdc-ce   Author: erigones   File:    License: Apache License 2.0 5 votes vote down vote up
def admin_network_form(request):
    Ajax page for updating, removing and adding networks.
    qs = request.GET.copy()

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

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

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

        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 = (,)
                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', '')}) 
Example 5
Project: esdc-ce   Author: erigones   File:    License: Apache License 2.0 5 votes vote down vote up
def network_ip_form(request, name):
    Ajax page for updating, removing and adding network IP address(es).
        net = Subnet.objects.get(name=name)
    except Subnet.DoesNotExist:
        raise Http404

    form_class = NetworkIPForm

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

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

    if form.is_valid():
        status =

        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',, query_string=request.GET)

    return render(request, form.template, {'form': form, 'net': {'name': name}}) 
Example 6
Project: esdc-ce   Author: erigones   File:    License: Apache License 2.0 5 votes vote down vote up
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

        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')\
    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) 
Example 7
Project: junction   Author: pythonindia   File:    License: MIT License 4 votes vote down vote up
def create_proposal_comment(request, conference_slug, proposal_slug):
    conference = get_object_or_404(Conference, slug=conference_slug)
    proposal = get_object_or_404(Proposal, slug=proposal_slug, conference=conference)
    form = ProposalCommentForm(request.POST)

    if request.user.is_active is False:
        raise PermissionDenied()

    if form.is_valid():
        comment = form.cleaned_data["comment"]
        private = form.cleaned_data["private"]
        reviewer = form.cleaned_data["reviewer"]

        has_perm = permissions.is_proposal_author_or_proposal_section_reviewer(
            user=request.user, conference=conference, proposal=proposal

        if private and not has_perm:
            raise Http404()

        proposal_comment = ProposalComment.objects.create(
        host = "{}://{}".format(settings.SITE_PROTOCOL, request.META.get("HTTP_HOST"))

        if settings.USE_ASYNC_FOR_EMAIL:
            send_mail_for_new_comment.delay(, host)
            send_mail_for_new_comment(, host)

    redirect_url = reverse("proposal-detail", args=[conference.slug, proposal.slug])

    if private:
        redirect_url += "#js-reviewers"
    elif reviewer:
        redirect_url += "#js-only-reviewers"
        redirect_url += "#js-comments"

    return HttpResponseRedirect(redirect_url) 
Example 8
Project: eoj3   Author: F0RE1GNERS   File:    License: MIT License 4 votes vote down vote up
def get_queryset(self):
      queryset = self.get_selected_from().select_related('problem', 'author'). \
        only('pk', 'contest_id', 'create_time', 'author_id', 'author__username',
             'author__magic', 'problem_id', 'problem__title', 'lang', 'status', 'status_time', 'status_percent',
             'code_length', 'ip', 'status_test', 'status_memory', 'visible', 'judge_server', 'contest_time')

      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:
        problem_id = self.reinterpret_problem_identifier(self.request.GET['problem'])
          if is_problem_manager(self.request.user, Problem.objects.get(pk=problem_id)):
            self.privileged = True
          queryset = queryset.filter(problem_id=problem_id)
      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 is_admin_or_root(self.request.user):
        self.privileged = True
      if not self.privileged:
        queryset = queryset.filter(visible=True)
      if not self.privileged and not self.contest_submission_visible:
        queryset = queryset.filter(contest__isnull=True)

      ordering = self.get_ordering()
      if ordering is not None:
        if isinstance(ordering, str):
          ordering = (ordering,)
        queryset = queryset.order_by(*ordering)

      if self.distinct_by_author:
        author_set = set()
        res = []
        for submission in queryset.all():
          if submission.author_id not in author_set:
            if self.query_number and len(res) >= self.query_number:
        return res
        return queryset.all()[:self.query_number]
    except Exception as e:
      raise Http404(e)