美文网首页
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建立一个应用

    1.python manage.py startapp lists 4.views.py 5.运行python m...

  • 一、Web应用和web.xml文件

    1.1构建Web应用 徒手建立Web应用: 在任意目录下建立一个文件夹,命名为webDemo。 在webDemo文...

  • bifangback-django应用建立

    在django里,一般是先建立一个项目,然后,再根据此项目的用途,建立不同的App应用,用来组成一个完整的具体应用...

  • 6.django之模板

    一、首页视图模板 这里有两点需要注意:1.mamengli_blog命名空间包含的是mamengli_blog应用...

  • webpack2.0介绍起步

    webpack 是一个用来构建我们应用程序中的 JavaScript 模块的工具。webpack 通过快速建立应用...

  • Angular学习笔记1

    我们按照Angular官方教程开始建立第一个应用。 第一个应用 安装 node & npm Angular通过np...

  • Docker构建镜像小记

    #构建镜像: ##1.建立Git仓库 将应用代码拷入 ##2.建立一个名为Dockerfile的文件 内容为下: ...

  • Android.js - 从 nodejs 构建 android

    如果你可以建立一个网站,你就可以建立一个 Android 应用程序!Android.js simple 将您的 n...

  • 建立联系,强化应用

    单位换算一直是历届学生的易错点,尤其是牵扯到小数的单位换算更是如此。错误的原因多种多样,大致有以下几种:进率掌握不...

  • angularJS之“自定义指令”

    应用场景 某一个特定的功能,我们要在应用程序内或程序之间进行复用 应用模板 当angularJS建立指令的每个实例...

网友评论

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

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