from django.contrib.sitemaps import Sitemap
from .models import Term


class TermsSitemap(Sitemap):
    changefreq = 'yearly'
    priority = 0.1

    def items(self):
        return Term.objects.all()

from django.contrib.sitemaps import Sitemap
from django.db.models import Q
from .models import Term


class TermsSitemap(Sitemap):
    changefreq = 'yearly'
    priority = 0.1

    def items(self):
        return Term.objects.filter(Q(url__startswith='/') | Q(url=''))

Exclude external urls from the sitemap.
Exclude external urls from the sitemap.

  from django.contrib.sitemaps import Sitemap
+ from django.db.models import Q
  from .models import Term
  
  
  class TermsSitemap(Sitemap):
      changefreq = 'yearly'
      priority = 0.1
  
      def items(self):
-         return Term.objects.all()
+         return Term.objects.filter(Q(url__startswith='/') | Q(url=''))
  
Exclude external urls from the sitemap.
## Code Before:
from django.contrib.sitemaps import Sitemap
from .models import Term


class TermsSitemap(Sitemap):
    changefreq = 'yearly'
    priority = 0.1

    def items(self):
        return Term.objects.all()

## Instruction:
Exclude external urls from the sitemap.
## Code After:
from django.contrib.sitemaps import Sitemap
from django.db.models import Q
from .models import Term


class TermsSitemap(Sitemap):
    changefreq = 'yearly'
    priority = 0.1

    def items(self):
        return Term.objects.filter(Q(url__startswith='/') | Q(url=''))
