《Python编程从入门到实践》18,19章 django 新版本代码更改 (2020.5)
对你有帮助的话,点个赞支持一下,蟹蟹
18.2.4 定义模型Entry
model.py
topic=models.ForeignKey(Topic)
改为
topic=models.ForeignKey(Topic,on_delete=models.CASCADE)
在后面19.3.2 外键都需要添加on_delete=models.CASCADE
models.py
owner=models.ForeignKey(User,on_delete=models.CASCADE)
18.3.1映射URL
from django.conf.urls import include,url
from django.contrib import admin
urlpatterns=[
url(r'^admin/,include(admin.site.urls)),
url(r'',include('learning_logs.urls',namespace='learning_logs')),
]
改为
from django.urls import path,include
......
urlpatterns=[
path('admin/',admin