Django sitemap http://example.com - программирование
Подтвердить что ты не робот

Django sitemap http://example.com

Извините за мой плохой английский, но я не английский!

Я пытаюсь создать файл sitemap.xml с моим проектом django.

В моем проекте у меня нет моделей (моя база данных пуста), у меня есть только статический url (например, "home" или "About" ).

Мне удалось создать файл sitemap.xml, но у меня есть http://example.com" вместо этого мое доменное имя.

Это мой sitemap.xml:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>
http://example.com/accueil
</loc>
<lastmod>
2013-03-14
</lastmod>
<changefreq>
weekly
</changefreq>
</url>
<url>
<loc>
http://example.com/cv
</loc>
<lastmod>
2013-03-14
</lastmod>
<changefreq>
weekly
</changefreq>
</url>
<url>
<loc>
http://example.com/portfolio
</loc>
<lastmod>
2013-03-14
</lastmod>
<changefreq>
weekly
</changefreq>
</url>
<url>
<loc>
http://example.com/a_propos
</loc>
<lastmod>
2013-03-14
</lastmod>
<changefreq>
weekly
</changefreq>
</url>
</urlset>

и my urls.py:

from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static

from sitemaps import BasicSitemap
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

sitemaps= {
    'pages' : BasicSitemap(['accueil','cv','portfolio','apropos'])
}

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'portfolio.views.home', name='home'),
    # url(r'^portfolio/', include('portfolio.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('portail_portfolio.urls')),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})

)

urlpatterns += staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

И мой файл sitemaps.py:

from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import reverse
#from portail_portfolio.models import Entry

from datetime import datetime

class BasicSitemap(Sitemap):

    def __init__(self, names):
        self.names = names

    def items(self):
        return self.names

    def changefreq(self, obj):
        return 'weekly'

    def lastmod(self, obj):
        return datetime.now()

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

Надеюсь, вы поймете мой английский, и я надеюсь, что вы можете мне помочь!

Сердечно,

суши

4b9b3361

Ответ 1

django.contrib.sitemaps полагается на django.contrib.sites.

Перейдите в раздел администратора /admin/sites/site/1/ и измените имя домена, которое вы там видите.