我在我的django项目中创建了一个startapp "guestbook“。
这是文件列表(留言簿)
__init__.py admin.py apps.py migrations models.py template tests.py urls.py views.py留言簿/模板
guestbookguestbook/模板/guestbook
index.html我想要获得索引渲染,但我面临错误,这是
File "C:\Users\_monster\Desktop\skill\django_frontend\backend\f_django\guestbook\urls.py", line 7, in <module>
path('', views.index, name='index')
AttributeError: module 'guestbook.views' has no attribute 'index'这是我的文件设置主urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
# main url, folder url
path('admin/', admin.site.urls),
path('hello/', include('hello.urls')),
path('guestbook/', include('guestbook.urls'))
]guestbook/urls.py
from django.urls import path
# import everything from views
from . import views
urlpatterns = [
path('', views.index, name='index')
]guestbook/views.py
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'guestbook/index.html')那么这里有什么问题呢?index.html在文件夹内
发布于 2020-09-17 03:37:22
我也犯了同样的错误。我几乎想尽一切办法来解决这个问题,但就是做不到。我刚刚将函数索引的名称从views.py更改为index2(guestbook/views.py)!然后我将这些更改复制到(guestbook/urls.py),如下所示
urlpatterns = [
path('', views.index2, name='index')
]它奇迹般地发生了。控制台不再显示错误!!当我再次切换回以前的模式(即从index2建立索引)时,一切都正常运行
https://stackoverflow.com/questions/51134098
复制相似问题