2016-12-17 1 views
0

블로그 부분과 내 웹 사이트의 주요 정적 부분에 대한 사이트 맵을 설정하려고합니다. 나는 문서를 파고 있었지만 내가 한 일은 이것을 고치기위한 것이 아니다. 나는 sitemap_main.py에서 네임 스페이스를 잘못 구현하고 있다고 생각하지만 이것은 문서에서 보이는 방식이다. 블로그 부분은 잘 작동하고 있으며 두 사이트 맵에 대한 링크를 제공하는 사이트 맵 색인 페이지를 받고 있습니다. 그러나 웹 사이트의 정적 부분에 대한 사이트 맵이 작동하지 않습니다. /sitemap-main.xml에서 NoReverseMatch를 얻습니다./sitemap-main.xml의 NoReverseMatch

NoReverseMatch at /sitemap-main.xml 
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 
Request Method: GET 
Request URL: http://127.0.0.1:8000/sitemap-main.xml 
Django Version: 1.8.6 
Exception Type: NoReverseMatch 
Exception Value:  
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 

웹 사이트/urls.py

from django.conf.urls import url 
from django.contrib.sitemaps.views import sitemap 

from .sitemap_main import StaticViewSitemap 
from . import views 

sitemaps = { 
    'static': StaticViewSitemap, 
} 

urlpatterns = [ 
    url(r'^$', views.index, name='home'), 
    url(r'index$', views.index, name='home'), 
    url(r'^gallery$', views.gallery, name='gallery'), 
    url(r'^contact$', views.contact, name='contact'), 
    url(r'^about$', views.about, name='about'), 
    url(r'^about/testimonial$', views.testimonial, name='about'), 
    url(r'^about/faq$', views.faq, name='about'), 
    url(r'^services$', views.services, name='services'), 
    url(r'^services/design$', views.design, name='design'), 
    url(r'^services/lawn-garden$', views.lawn, name='lawn'), 
    url(r'^services/irrigation$', views.irrigation, name='irrigation'), 
    url(r'^services/spring$', views.spring, name='spring'), 
    url(r'^services/hardscape$', views.hardscape, name='hardscape'), 
    url(r'^sitemap-main\.xml$', sitemap, {'sitemaps': sitemaps}, 
     name='django.contrib.sitemaps.views.sitemap') 

] 

sitemap_main.py는

from django.contrib import sitemaps 
from django.core.urlresolvers import reverse 


class StaticViewSitemap(sitemaps.Sitemap): 
    priority = 0.5 
    changefreq = 'daily' 

    def items(self): 
     return ['home', 'gallery', 'contact', 
       'services', 'design', 'lawn', 
       'irrigation', 'spring', 
       'hardscape'] 

    def location(self, item): 
     return reverse(item) 
+0

'website.urls' 파일에서 어떻게 당겨질 수 있습니까? 프로젝트의 다른 앱에는 3 개의 urls.py 파일이 있습니다. –

답변

1

는 알았어요! 네임 스페이스에 앱 이름을 사용하지 않았습니다. 수정 됨 -

from django.contrib import sitemaps 
from django.core.urlresolvers import reverse 


class StaticViewSitemap(sitemaps.Sitemap): 
    priority = 0.5 
    changefreq = 'daily' 

    def items(self): 
     return ['website:home', 'website:gallery', 'website:contact', 
       'website:services', 'website:design', 'website:lawn', 
       'website:irrigation', 'website:spring', 
       'website:hardscape'] 

    def location(self, item): 
     return reverse(item)