简体   繁体   English

django sitemap http://example.com

[英]django sitemap http://example.com

Sorry for my bad english but i'm not english! 抱歉我的英语不好,但我不是英国人!

I try to generate a sitemap.xml with my django project. 我尝试用我的django项目生成一个sitemap.xml。

In my project i don't have models (my database is empty), i have just static url (like 'home' or 'About' ). 在我的项目中我没有模型(我的数据库是空的),我只有静态网址(比如'home'或'About')。

I succeded to generate a sitemap.xml but i have " http://example.com " instead that my domain name. 我成功生成了一个sitemap.xml,但我有“ http://example.com ”而不是我的域名。

This is my sitemap.xml: 这是我的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>

and my urls.py: 和我的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)

And my sitemaps.py: 和我的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)

I hope you can understand my english and i hope you can help me! 我希望你能理解我的英语,我希望你能帮助我!

Cordially, 亲切,

sushi 寿司

django.contrib.sitemaps relies on django.contrib.sites . django.contrib.sitemaps依赖于django.contrib.sites

Go into your admin section /admin/sites/site/1/ and change the domain name you see there. 进入您的管理部分/admin/sites/site/1/并更改您在那里看到的域名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM