我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.views.View()。
def get(self, request, *args, **kwargs): form = SubmitForm() return render(request, 'join.html', {'form': form}) # class NavView(View): # """ nav bar """ # def get(self, request): # site_name = PROJECT_NAME # context = site_name # return render(request, 'nav.html', context)
def get(self, request): """ View for default page of logged user. Returns relevant posts list. """ # GET PARAMETERS place = request.user.vkuser.place if not request.GET.get('place') else request.GET.get('place') tag = "any" if not request.GET.get('tag') else request.GET.get('tag') order = "desc" if not request.GET.get('order') else request.GET.get('order') is_anonymous = 'any' if not request.GET.get('is_anonymous') else request.GET.get('is_anonymous') # FILTER POSTS filtered_posts = filter(place, tag, order, is_anonymous) # RESOLVE AD ad = None if Ad.objects.filter(place=-1).exists(): ad = Ad.objects.filter(place=-1).first() elif Ad.objects.filter(place=request.user.vkuser.place).exists(): ad = Ad.objects.filter(place=request.user.vkuser.place).first() # INIT PAGINATOR filtered_posts_paginator = Paginator(filtered_posts, self.post_per_request) # BUILD CONTEXT context = {} filtered_posts_page = filtered_posts_paginator.page(1) context = { 'posts_list': filtered_posts_page, 'has_next': filtered_posts_page.has_next(), 'next_page': filtered_posts_page.next_page_number() if filtered_posts_page.has_next() else 0, 'VK_BASE_URL': settings.VK_BASE_URL, 'ad': ad } return render(request, self.template_name, context)