学习笔记

时间:2021-10-15 19:16:36

在按照书上的步骤敲代码的时候遇见的一些问题以及搜集的解决办法

18.1.2 建立虚拟环境

在使用书上的代码

python -m venv mp_env

创建虚拟环境时会报错

Error: Command '['E:\\python_py\\ex\\ex18_5\\meal_planner\\mp_env\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

修改成

python -m venv --without-pip mp_env

之后就没有问题了

18.2.4 定义模型Entry

在使用书上的代码

topic = models.ForeignKey(Topic)

时报错

TypeError: __init__() missing 1 required positional argument: 'on_delete'

修改成

topic = models.ForeignKey('Topic', on_delete=models.CASCADE)

18.3.1 映射URL

报错:

django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

learning_log中的urls.py(项目中)

url(r'^admin/', include(admin.site.urls))

去掉include改为

url(r'^admin/', admin.site.urls)

报错:

django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

learning_logs中的urls.py(应用程序中)

urlpatterns = [……]前面加上

app_name = '[#]'(其中#为你的应用程序名称)