django sitemap root url not showing up
my sitemap.xml file is showing every url of my apps as it should do. but the main /-url (root-url) of my domain is not in the sitemap.xml because its not an app. and there are no models for the main-page. but as you can see in sitemap.py (see below) one needs a model and an app to return something for creating an entry in the sitemap. b开发者_如何学编程ut my main-page has no referenced data in the database, so i don't know what to return.
how should i resolve that problem? [i tried with flatpages but django-flatpages didn't help me either, because i could not tell the admin-interface to create a page with the url "/", it wanted something like "/about/temp.html/".]
my project-directory is looking similar to this:
projectname/app1 /app2 /app3 settings.py local_settings.py sitemap.py etc...
sitemap.py
from django.contrib.sitemaps import Sitemap from app1.models import ModelX from app2.models import ModelY class SitemapApp1(Sitemap): priority = 0.5 def items(self): return ModelX.objects.all() class SitemapApp2(Sitemap): priority = 0.5 def items(self): return ModelY.objects.all()
what i have tried is: i created an app called main with a models.py in it. And in this model i wanted to do somethings stupid, just to have a model now for the main / url, beeing able to return something.
class Main(models.Model): name = models.CharField(max_length=64, unique=False, blank=True) def __unicode__(self): return self.name
projectname/app1 /app2 /app3 /main models.py __init__.py settings.py local_settings.py etc. sitemap.py
sitemap.py new
from django.contrib.sitemaps import Sitemap from app1.models import ModelX from app2.models import ModelY from main.models import Main class SitemapApp1(Sitemap): priority = 0.5 def items(self): return ModelX.objects.all() class SitemapApp2(Sitemap): priority = 0.5 def items(self): return ModelY.objects.all() class SitemapMain(Sitemap): priority = 0.5 def items(self): return Main.objects.all()
Sure, restarted the server. Well it doesn't give me an error when i go to domain.com/sitemap.xml but i doesn't show up with domain.com-entry in sitemap.xml either.
So i am sure, you have a much better solution to my stupid approach of getting domain.com/ root into sitemap.xml.
Appreciat your help. Thanks a lot in advance!
sc
You could try and modify this example I got from here:
class MainSitemap(Sitemap):
def items(self):
return [self]
location = "/"
changefreq = "monthly"
priority = "1"
精彩评论