網站首頁 編程語言 正文
在django
中,ORM(對象關系映射器—object-relational mapper
)任務是:模型化數據庫,創建數據庫由另外一個系統負責(遷移–migration
),遷移任務是根據對models.py
文件的改動情況,添加或者刪除表和列
依然報錯:
models.py
from django.db import models class Item(models.Model): ? ? text=models.TextField(default='')
tests.py
'''from django.test import TestCase # Create your tests here. class Smokeclass(TestCase): ? ? def test_bad_maths(self): ? ? ? ? self.assertEquals(1+1,3)''''' from ?django.urls import ?resolve from ?django.test import ?TestCase from lists.views import ?home_page from django.http import ?HttpRequest from lists.models import Item class HomePageTest(TestCase): ? ? def test_root_url_resolve_to_home_page_view(self): ? ? ? ? found=resolve('/') ? ? ? ? # resolve函數是django內部使用的函數,用于解析url, ? ? ? ? # 并且將其映射到相應的視圖函數上,檢查網站根路徑時"/", ? ? ? ? # 是否能找到home_page函數 ? ? ? ? self.assertEquals(found.func,home_page) ? ? def test_home_page_returns_correct_html(self): ? ? ? ? request=HttpRequest() ? ? ? ? # 創建httprequest對象,用戶在瀏覽器中請求網頁時 ? ? ? ? # django看到的就是httprequest對象 ? ? ? ? response=home_page(request) ? ? ? ? # 把對象傳給home_page視圖 ? ? ? ? html=response.content.decode('utf8') ? ? ? ? # 提取content,得到結果是原始的字節,即發個用戶 ? ? ? ? # 瀏覽器的0和1,隨后調用.decode(),把原始字節 ? ? ? ? # 轉換成發給用戶的html字符串 ? ? ? ? self.assertTrue(html.startswith('')) ? ? ? ? self.assertIn('To-Do lists ',html) ? ? ? ? self.assertTrue(html.endswith(')) ?self.assertTemplateUsed(response,'home.html') ? ? def test_user_home_template(self): ? ? ? ? response=self.client.get('/') ? ? ? ? self.assertTemplateUsed(response,'home.html') ? ? def test_can_save_a_POST_request(self): ? ? ? ? response=self.client.post('/',data={'item_text':'a new list item'}) ? ? ? ? self.assertIn('a new list item',response.content.decode()) ? ? ? ? self.assertTemplateUsed(response, 'home.html') class ItemModelTest(TestCase): ? ? def test_saving_and_retrieving_items(self): ? ? ? ? first_item=Item() ? ? ? ? first_item.text="the first list item" ? ? ? ? first_item.save() ? ? ? ? second_item = Item() ? ? ? ? second_item.text = "the second list item" ? ? ? ? second_item.save() ? ? ? ? saved_items=Item.objects.all() ? ? ? ? self.assertEquals(saved_items.count(),2) ? ? ? ? first_saved_item=saved_items[0] ? ? ? ? second_saved_item=saved_items[1] ? ? ? ? self.assertEquals(first_saved_item.text,'the first list item') ? ? ? ? self.assertEquals(second_saved_item.text, 'the second list item')
python manage.py makemigrations
原文鏈接:https://blog.csdn.net/weixin_39349045/article/details/123034530
相關推薦
- 2022-03-04 element-ui修改tooltip的背景顏色和小箭頭的顏色
- 2022-09-25 文本文件與二進制文件的區別
- 2022-06-04 python函數的兩種嵌套方法使用_python
- 2024-04-06 @Delete通過批量刪除的方法
- 2024-02-29 UNI-APP中點擊事件多重響應問題的解決,list列表項item和列表項item中按鈕的點擊事件沖
- 2023-02-10 Redis如何正確關閉和開啟持久化_Redis
- 2022-10-02 iOS實現簡易的抽屜效果_IOS
- 2022-07-20 C語言詳細講解while語句的用法_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支