我搞不懂为什么OfertoHome视图有效,而OfertoListView不起作用,它们都是一样的-唯一不同的是在url中。在
class OfertoListView(ListView):
model = Oferto
paginate_by = 10
template_name = "ofertoj/oferto_list.html"
def get_context_data(self,**kwargs):
context = super(OfertoListView,self).get_context_data(**kwargs)
return context
class OfertoHome(ListView):
model = Oferto
paginate_by = 10
template_name = "ofertoj/oferto_list.html"
def get_context_data(self,**kwargs):
context = super(OfertoHome,self).get_context_data(**kwargs)
return context
在网址.py在
^{pr2}$调试消息
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/oferto/listview/
No oferto found matching the query
这是我的全部视图.py在应用程序中,已发布,因为请求
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ofertoj.views
from .models import Oferto
from django.views.generic import CreateView, UpdateView, DetailView
from django.views.generic import ListView
from turtle.views import Turtle_CreateView,ActionMixin,NameSearchMixin
from braces.views import LoginRequiredMixin
from forms import OfertoCreateForm,OfertoUpdateForm
class OfertoCreateView(LoginRequiredMixin,Turtle_CreateView):
model = Oferto
action = "created"
form_class = OfertoCreateForm
class OfertoDetailView(DetailView):
model = Oferto
class OfertoResultsView(OfertoDetailView):
template_name = "Oferto/results.html"
class OfertoUpdateView(LoginRequiredMixin,ActionMixin,UpdateView):
model = Oferto
action = "created"
form_class = OfertoUpdateForm
class OfertoListView(ListView):
model = Oferto
paginate_by = 10
template_name = "ofertoj/oferto_list.html"
def get_context_data(self,**kwargs):
context = super(OfertoListView,self).get_context_data(**kwargs)
return context
class OfertoHome(ListView):
model = Oferto
paginate_by = 10
template_name = "ofertoj/oferto_list.html"
def get_context_data(self,**kwargs):
context = super(OfertoHome,self).get_context_data(**kwargs)
return context
在网址.py在
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ofertoj/urls.py
from django.conf.urls import patterns, url
from views import *
urlpatterns = patterns("",
url(
regex=r"^createview/$",
view=OfertoCreateView.as_view(),
name="oferto_createview"
),
url(
regex=r"^(?P<slug>[-_\w]+)/$",
view=OfertoDetailView.as_view(),
name="oferto_detail"
),
url(
regex=r"^(?P<slug>[-_\w]+)/$/results/$",
view=OfertoResultsView.as_view(),
name="oferto_results"
),
url(
regex=r"^listview/$",
view=OfertoListView.as_view(),
name="oferto_listview"
),
url(
regex=r"^(?P<slug>[-_\w]+)/updateview/$",
view=OfertoUpdateView.as_view(),
name="oferto_updateview"
),
url(
regex=r"^$",
view = OfertoHome.as_view(),
name ="oferto_home"
),
)
它可能会选择一个细节视图,并寻找一个名为
listview
的pk或slug的Oferto,但没有发现它产生404。请把你的全部网址.py找出冲突。在是的,你的网址.py按顺序解析,第一个匹配的是已处理的视图。在您的例子中,
oferto_detail
url中的r"^(?P<slug>[-_\w]+)/$"
与url中的输入“listview”匹配。将listview/$
url放在第一位,它应该可以正常工作。在相关问题 更多 >
编程相关推荐