Django отображение адресов на представления
ModuleNotFoundError: Нет модуля с именем 'playground/urls' Я изучаю серию книг ultimate django от Моша Хамедани и столкнулся с проблемой. Я сделал все точно так же, как он, но у меня ничего не получилось. Вот мой urls.py и установленные приложения.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
'playground'
]
playground/urls.py
from django.urls import path
from . import views
#URLConf
urlpatterns = [
path('hello/', views.say_hello)
]
storefront/urls.py
"""storefront URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('playground/', include('playground/urls'))
]
возможно, используя include('appname.urls')
изменение
path('playground/', include('playground/urls'))
to
path('playground/', include('playground.urls'))
Попробуйте :
path('playground/', include('playground.urls'))
Инстинкт:
path('playground/', include('playground/urls'))
Вы можете проверить эту часть на Django tutorial
Надеемся, что это поможет вам!
если вы напишите, что выдает терминал, это тоже иногда бывает полезно, как я понимаю Модель не существует,
попробуйте python mange.py makemigrations