模块未找到错误Python Django

时间:2018-02-25 02:18:24

标签: python django url mapping

我正在尝试将基本URL映射到我的“学习日志”主页。这是我在主 urls.py文件中的以下代码:

from django.contrib import admin
from django.urls import path
from django.urls import include


urlpatterns = [
    path('admin/', admin.site.urls),
    path(r' ', include('learning_logs.urls', namespace='learning_logs')),
]

我保存文件并查看终端以查看是否存在任何问题并且它会发出以下错误: ModuleNotFoundError:没有名为'learning_logs.urls'的模块

我不对python / django和一本叫做python速成课程的书。不知道我做错了什么,请帮忙!

1 个答案:

答案 0 :(得分:0)

最好的解决方案是检查作者的更新: http://ehmatthes.github.io/pcc/chapter_18/README.html#updates

urls.py

的更新
from django.urls import path, include
from django.contrib import admin

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('learning_logs.urls')),
]

learning_logs / urls.py

的更新
"""Defines url patterns for learning_logs."""

from django.urls import path

from . import views

app_name = 'learning_logs'
urlpatterns = [
    # Home page.
    path('', views.index, name='index'),
]