美文网首页
6.django建立一个应用

6.django建立一个应用

作者: abrila | 来源:发表于2019-01-03 13:15 被阅读0次

    1.python manage.py startapp lists

    image.png
    2. image.png
    3.test.py
    from django.test import TestCase
    from django.test import TestCase
    from django.test import TestCase
    from lists.views import home_page
    from django.urls import resolve
    from django.http import HttpRequest
    # Create your tests here.
    class HomePageTest(TestCase):
        def test_root_url_resloves_to_home_page_view(self):
            found = resolve('/')
            self.assertEqual(found.func,home_page)
        def test_home_page_returns_correct_html(self):
            request = HttpRequest()
            response = home_page(request)
            html = response.content.decode('utf-8')
            self.assertTrue(html.startswith('<html>'))
            self.assertIn('<title>To-Do lists</title>',html)
            self.assertTrue(html.endswith('</html>'))
    
    

    4.views.py

    from django.shortcuts import render
    from django.http import HttpResponse
    
    # Create your views here.
    def home_page(request):
        return HttpResponse('<html><title>To-Do lists</title></html>')
    

    5.运行python manage.py test

    image.png

    相关文章

      网友评论

          本文标题:6.django建立一个应用

          本文链接:https://www.haomeiwen.com/subject/nexfrqtx.html