我刚开始在Django中使用基于类的视图。当我试图启动服务器,我得到这个错误: 这是我的代码: urls . py
from . import views
from django.urls import path
app_name = 'food'
urlpatterns = [
path('', views.IndexClassView.as_view(), name = 'index'),
path('item/', views.item, name = 'item'),
path('info/', views.info, name = "info"),
path('<int:pk>/', views.FoodDetail.as_view(), name = "detail" ),
#add form
path('add', views.create_item, name = "create"),
#edit item
path('update/<int:id>/', views.update_item, name = 'update_item'),
#delete item
path(r'^delete/<int:id>/', views.delete_item, name = 'delete_item')
]
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect
from .models import Item
from django.template import loader
from .forms import ItemForm
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from djange.views.genereic.edit import CreateView
class IndexClassView(ListView):
model = Item
template_name = 'food/index.html'
context_object_name = 'item_list'
def detail(request, item_id):
item = Item.objects.get(pk = item_id)
context = {
'item' : item,
}
return render(request, 'food/detail.html', context)
class FoodDetail(DetailView):
model = Item
template_name = 'food/detail.html'
...
那食物怎么可能。当视图在我眼前定义时,它没有FoodDetail属性!? 问题来源StackOverflow 地址:/questions/59381012/why-is-python-giving-me-an-attributeerror-even-if-i-have-defined-that-particular
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。