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


Python base.View方法代码示例

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


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

示例1: test_update_get_object

# 需要导入模块: from django.views.generic import base [as 别名]
# 或者: from django.views.generic.base import View [as 别名]
def test_update_get_object(self):
        a = Author.objects.create(
            pk=1,
            name='Randall Munroe',
            slug='randall-munroe',
        )
        res = self.client.get('/edit/author/update/')
        self.assertEqual(res.status_code, 200)
        self.assertIsInstance(res.context['form'], forms.ModelForm)
        self.assertIsInstance(res.context['view'], View)
        self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
        self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
        self.assertTemplateUsed(res, 'generic_views/author_form.html')

        # Modification with both POST and PUT (browser compatible)
        res = self.client.post('/edit/author/update/', {'name': 'Randall Munroe (xkcd)', 'slug': 'randall-munroe'})
        self.assertEqual(res.status_code, 302)
        self.assertRedirects(res, '/list/authors/')
        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>']) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_edit.py

示例2: get

# 需要导入模块: from django.views.generic import base [as 别名]
# 或者: from django.views.generic.base import View [as 别名]
def get(self, request):
        # django自带的logout
        logout(request)
        from django.core.urlresolvers import reverse
        # 重定向到首页,
        return HttpResponseRedirect(reverse("index"))


# ----------------------登陆业务逻辑---------------------------------
# class LoginView(View):
#     def get(self, request):
#         return render(request, "login.html", {})
#
#     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 render(request, "index.html")
#                 else:
#                     return render(request, "login.html", {"msg": "用户未激活!"})
#             else:
#                 return render(request, "login.html", {"msg": "用户名或密码错误!"})
#         else:
#                 return render(request, "login.html", {"msg": "用户名或密码错误!", "login_form": login_form}) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:31,代码来源:views.py

示例3: test_queryset

# 需要导入模块: from django.views.generic import base [as 别名]
# 或者: from django.views.generic.base import View [as 别名]
def test_queryset(self):
        res = self.client.get('/list/authors/')
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'generic_views/author_list.html')
        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
        self.assertIsInstance(res.context['view'], View)
        self.assertIs(res.context['author_list'], res.context['object_list'])
        self.assertIsNone(res.context['paginator'])
        self.assertIsNone(res.context['page_obj'])
        self.assertFalse(res.context['is_paginated']) 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_list.py

示例4: test_simple_object

# 需要导入模块: from django.views.generic import base [as 别名]
# 或者: from django.views.generic.base import View [as 别名]
def test_simple_object(self):
        res = self.client.get('/detail/obj/')
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.context['object'], {'foo': 'bar'})
        self.assertIsInstance(res.context['view'], View)
        self.assertTemplateUsed(res, 'generic_views/detail.html') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_detail.py

示例5: test_create

# 需要导入模块: from django.views.generic import base [as 别名]
# 或者: from django.views.generic.base import View [as 别名]
def test_create(self):
        res = self.client.get('/edit/authors/create/')
        self.assertEqual(res.status_code, 200)
        self.assertIsInstance(res.context['form'], forms.ModelForm)
        self.assertIsInstance(res.context['view'], View)
        self.assertNotIn('object', res.context)
        self.assertNotIn('author', res.context)
        self.assertTemplateUsed(res, 'generic_views/author_form.html')

        res = self.client.post('/edit/authors/create/', {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
        self.assertEqual(res.status_code, 302)
        self.assertRedirects(res, '/list/authors/')
        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:test_edit.py


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