Ich habe ein Problem beim Implementieren der Sitemaps in meiner Anwendung. Ich benutze Virtualenv, Django 1.4 und Python 2.7. Ich würde mich freuen, wenn Sie mir helfen können, dies zu lösen.Implementieren von Sitemaps in Django
Dies ist, was ich getan habe:
In meinem urls.py
from sitemap import JobPostSitemap sitemaps = { 'jobs': JobPostSitemap, } ... # Removed other urls url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
Dann in meiner sitemap.py Datei
from django.contrib.sitemaps import Sitemap from jobs.models import JobPost class JobPostSitemap(Sitemap): changefreq = "never" priority = 0.5 def items(self): return JobPost.objects.filter(approved=True) def lastmod(self, obj): return obj.pub_date
Mein settings.py Datei ist wie folgt:
TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) ... INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sitemaps', 'jobs', ) ...
Nun, wenn ich meinen Browser öffnen und navigieren Sie zu http://localhost:8000/sitemap.xml
, bekomme ich folgende Fehlermeldung:
ImportError at /sitemap.xml
No module named django.contrib.sitemaps
Request Method: GET
Request URL: http://localhost:8000/sitemap.xml
Django Version: 1.4.2
Exception Type: ImportError
Exception Value:
No module named django.contrib.sitemaps
Exception Location: /home/frank/Projects/python/django/techjobsea.com/baseline27/local/lib/python2.7/site-packages/Django-1.4.2-py2.7.egg/django/utils/importlib.py in import_module, line 35
Python Executable: /home/frank/Projects/python/django/techjobsea.com/baseline27/bin/python
Python Version: 2.7.3
ich kann nicht herausfinden, was ich verpasst habe oder falsch zu machen.
Haben Sie alle erforderlichen Installationsschritte für 'sitemap' verfolgt? Die erforderlichen Schritte [hier] (https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/) – doru
@doru Ja. Ich folgte den ganzen Schritten. – Frankline
Haben Sie eine Lösung gefunden? –