簡體   English   中英

Django 將 URL 映射到視圖

[英]Django mapping urls to views

ModuleNotFoundError: No module named 'playground/urls' 我正在瀏覽 mosh hamedani 的終極 django 系列,我遇到了一個問題。 我完全按照他的做法做了,但對我沒有用。 這是我的 urls.py 和已安裝的應用程序。

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
'playground'

]

游樂場/urls.py

from django.urls import path
from . import views

    #URLConf
    urlpatterns = [
        path('hello/', views.say_hello)
    ]

店面/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'))

path('playground/', include('playground.urls'))

嘗試:

 path('playground/', include('playground.urls'))

代替:

 path('playground/', include('playground/urls'))

您可以在Django 教程上查看該部分

希望對你有幫助!

如果您發布終端給您的內容,這有時也會有所幫助,據我所知 Model 不存在,

嘗試 python mange.py makemigrations

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM