django 站点地图根 url 未显示
我的 sitemap.xml 文件显示了我的应用程序的每个 url,因为它应该这样做。 但我的域的主 /-url (root-url) 不在 sitemap.xml 中,因为它不是应用程序。 并且主页没有模型。但正如您在 sitemap.py 中看到的那样(见下文) 人们需要一个模型和一个应用程序来返回一些内容,以便在站点地图中创建条目。 但我的主页在数据库中没有引用的数据,所以我不知道要返回什么。
我应该如何解决这个问题? [我尝试使用 Flatpages,但 django-flatpages 也没有帮助我,因为我无法告诉管理界面创建带有 url“/”的页面,它想要类似“/about/temp.html/”的内容。 ]
我的项目目录看起来与此类似:
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()
我尝试过的是: 我创建了一个名为 main 的应用程序,其中包含 models.py。在这个模型中,我想做一些愚蠢的事情,只是为了现在为主 / url 建立一个模型,能够返回一些东西。
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()
当然,重新启动服务器。 当我访问domain.com/sitemap.xml 时,它不会给我错误 但我也没有在 sitemap.xml 中显示domain.com-entry。
所以我确信,对于我将domain.com/ root 放入sitemap.xml 的愚蠢方法,您有更好的解决方案。
感谢您的帮助。 预先非常感谢!
SC
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.
but 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试修改我得到的这个示例 从这里开始:
You could try and modify this example I got from here: