基于slugs的链接给出了错误

时间:2017-12-12 22:08:23

标签: python django

我有这个链接url:

<a href="{% url 'listings:listing_detail' list.l_slug %}" class="btn btn-primary">See More</a>

它将它引导到我的应用的这个网址模式:

from django.conf.urls import url
from listings import views

app_name = 'listings'

urlpatterns = [
    url(r'^$',views.UniversityListView.as_view(),name='universities'),
    url(r'^/(?P<name_initials>\w+)$',views.ListingView.as_view(),name='listing_detail'),
]

以下是项目网址模式:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$',views.HomeView.as_view(),name='index'),
    url(r'^(?P<u_slug>[-\w]+)/$',views.UniversityHomePageView.as_view(),name='university_homepage'),
    url(r'^(?P<u_slug>[-\w]+)/',include('listings.urls',namespace='listings')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

但是我收到了这个错误:

django.urls.exceptions.NoReverseMatch: Reverse for 'listing_detail' with arguments '('stafford-apartments',)' not found. 1 pattern(s) tried: ['(?P<u_slug>[-\\w]+)//(?P<name_initials>\\w+)$']

Django:1.11

修改

以下是详细信息视图:

class ListingView(DetailView):
    model = Listing
    company = Company.objects.all()
    university = University.objects.all()
    context = {
            'listing':model,
            'company':company,
            'university':university,
            }

1 个答案:

答案 0 :(得分:0)

如错误所示,您的listing_detail网址需要两个参数 - u_slug和name_initials - 但您只提供一个参数。