获取错误:模块未找到错误:python中没有名为“trialrisk.urls”的模块

nwwlzxa7  于 2022-11-21  发布在  Python
关注(0)|答案(2)|浏览(137)

我是django python的新手,现在我正在使用rest api,所以我创建了新的应用程序trialrisk,首先我在settings.py文件中添加了我的应用程序,之后当我尝试在www.example.com文件中添加urlurls.py时,我收到了一个错误:ModuleNotFoundError: No module named 'trialrisk.urls' in python,在这里我已经添加了整个代码和我的文件夹结构,任何人都可以请看我的代码,并帮助我解决这个问题?
文件夹结构

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'trialrisk',
]

urls.py

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

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

vwhgwdsa1#

trialriskurls.py文件夹中没有www.example.com文件。请在trialrisk文件夹中创建相同的文件并从中导入。

46qrfjad

46qrfjad2#

除了将www.example.com添加urls.py到trialrisk之外,您还必须向其添加一个urlpatterns对象,例如urlpatterns = [],否则您将得到如下错误
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'trialrisk.urls' from '/pathtoyourproject/trialrisk/urls.py'>' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.

相关问题