新django,真的很喜歡簡單的工作完成。然而,當我得到一個不支持的405錯誤聲明方法時,出現通用DetailView的問題。以下是我的代碼。django通用DetailView
from django.shortcuts import render, get_object_or_404, get_list_or_404
from django.views.generic import View, ListView, DetailView
from store.managers import StoreManager
from .models import Store
# Create your views here.
class StoreDetails(DetailView):
model = Store
template_name = 'store/details.html'
class StoreIndex(ListView):
model = Store
template_name = 'store/index.html'
context_object_name = 'stores'
# url
urlpatterns = [
url(r'^view/([0-9]+)/$', StoreDetails.as_view(), name='details'),
url(r'^index/$', StoreIndex.as_view(), name='index'),
]
雖然我的StoreIndex視圖完美地工作,但我的StoreDetails視圖出現錯誤。嘗試覆蓋get_context_data函數,但結果相同。
請問您可以添加您的'urls'嗎? – RodrigoDela
這是我的網址:urlpatterns = [url(r'^ view /([0-9] +)/ $',StoreDetails.as_view(),name ='details'),] –
您是否嘗試添加'get功能到你的觀點? – RodrigoDela