我想顯示的網址從我的website.urls我的sitemap.xml文件文件NoReverseMatch在/sitemap.xml的Django與StaticViewSitemap從app.urls
從這個URL文件我沒有煩惱,以顯示條款隱私等
網址
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles import views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
from django.conf.urls import * # NOQA
from django.conf.urls.i18n import i18n_patterns
from django.contrib.sitemaps.views import sitemap
from .sitemaps import StaticViewSitemap
from . import views
sitemaps = {
'static': StaticViewSitemap,
}
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('website.urls')),
url(r'^terms/$', views.terms, name='terms'),
url(r'^privacy/$', views.privacy, name='privacy'),
url(r'^cdg/$', views.cdg, name='cdg'),
url(r'^about/$', views.about, name='about'),
url(r'^icon/$', views.icon, name='icon'),
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap')
]
# This is only needed when using runserver.
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', # NOQA
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
) + staticfiles_urlpatterns() + urlpatterns # NOQA
但是,當我想從另一個URL文件的意見(這是一個應用程序的url文件位於子文件夾內)我有一個錯誤。
這裏是我的sitemap.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 ['terms','privacy', 'about', 'cdg','support']
def location(self, item):
return reverse(item)
這裏是website.url PY文件
from django.conf.urls import patterns, url
from . import views
app_name = 'website'
urlpatterns = patterns('',
url(r'^support/$', views.support, name='support'),
url(r'^galerie/$', views.galerie, name='galerie'),
url(r'^showcase/$', views.showcase, name='showcase'),
url(r'^blog/$', views.blog, name='blog'),
)
我有這個錯誤:
NoReverseMatch at /sitemap.xml
Reverse for 'support' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://localhost:8000/sitemap.xml
Django Version: 1.9.9
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'support' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: /Users/R/Virtualenvs/p3-dj1_9/lib/python3.5/site-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 508
任何幫助將不勝感激