简体   繁体   English

Django 将 URL 映射到视图

[英]Django mapping urls to views

ModuleNotFoundError: No module named 'playground/urls' I am going through the ultimate django series by mosh hamedani and i came across a problem. ModuleNotFoundError: No module named 'playground/urls' 我正在浏览 mosh hamedani 的终极 django 系列,我遇到了一个问题。 I did exactly as he did and it didn't work for me.我完全按照他的做法做了,但对我没有用。 Here are my urls.py and installed apps.这是我的 urls.py 和已安装的应用程序。

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

] ]

playground/urls.py游乐场/urls.py

from django.urls import path
from . import views

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

storefront/urls.py店面/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'))
]

maybe using include('appname.urls')也许使用 include('appname.urls')

change改变

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

to

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

Try:尝试:

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

Insteed of:代替:

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

You can check that part on Django tutorial您可以在Django 教程上查看该部分

Hope that help you !希望对你有帮助!

if you post what the terminal gives you that's also sometimes is helpful, as i understand it The Model Does not exist,如果您发布终端给您的内容,这有时也会有所帮助,据我所知 Model 不存在,

try python mange.py makemigrations尝试 python mange.py makemigrations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM