我已完成整个过程,这似乎相当简单,无法设置sitemap.xml文件。
当我访问www.example.com/sitemap.xml'页面未找到时,我收到了404页面'和消息(我仍然打开了调试设置......)沿着以下几行:
" Django tried these URL patterns, in this order:
^admin/
^nday/
^ ^$ [name='index']
^ ^tomorrow/$ [name='tomorrow']
^ ^day/(?P<day_name_url>\w+)/$ [name='day']
The current URL, sitemap.xml, didn't match any of these."
这是我的urls.py文件
from django.conf.urls import patterns, url
from django.contrib.sitemaps.views import sitemap
from nday import views
from nday import sitemap
from nday.sitemap import ndaySitemap
sitemaps = {
'posts': ndaySitemap,
}
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^tomorrow/$', views.tomorrow, name='tomorrow'),
url(r'^day/(?P<day_name_url>\w+)/$', views.day, name='day'),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),)
和我的sitemap.py文件..
from django.contrib.sitemaps import Sitemap
from nday import models
from nday.models import nationalday
class ndaySitemap(Sitemap):
changefreq = "daily"
priority = 0.5
def items(self):
return nationalday.objects.all()
我已根据settings.py文件安装了站点地图..
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
'nday',
)
非常感谢你提前
答案 0 :(得分:1)
如果您使用的是Django开发服务器,则在进行任何代码更改时应重新加载。
但是在生产中(例如Apache或Nginx),您必须在对.py
文件进行任何更改后重新加载服务器。