我正在学习Django,但在构建我的第一个方法的过程中,我遇到了这个问题。
ImportError:无法从“ __main __”(C:\ Users \ Kalyan Mohanty \ Documents \ GitHub \ Django \ rek \ calc \ urls.py)导入名称“视图”
在我的应用程序“ calc”文件夹下
urls.py
from django.urls import path
from . import views
urlspatterns = [
path('', views.home, name = 'home')
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib import admin
def home(request):
return HttpResponse('Hello world')
rek文件夹 urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('calc.urls')),
path('admin/', admin.site.urls),
]
结构
-calc (folder)
`-__pycache__ (folder)`
`-migrations (folder)`
`-__init__`
`-admin.py`
`-apps.py`
`-models.py`
`-test.py`
`-urls.py`
`-views.py`
-rek (folder)
`-__pycache__`
`-__init__`
`-settings.py`
`-urls.py`
`-wsgi.py`
db.sqlite3
manage.py
答案 0 :(得分:1)
您可以只使用导入视图。这对我有用