Skip to content

Commit

Permalink
Creating a sitemap using the sitemap framework
Browse files Browse the repository at this point in the history
  • Loading branch information
yahyaaly151989 committed Aug 27, 2023
1 parent ebc0bd5 commit 5b0487e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
Binary file not shown.
12 changes: 12 additions & 0 deletions Module03/mysite/blog/sitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib.sitemaps import Sitemap
from .models import Post

class PostSitemap(Sitemap):
changefreq = 'weekly'
priority = 0.9

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

def lastmod(self, obj):
return obj.updated
Binary file modified Module03/mysite/db.sqlite3
Binary file not shown.
Binary file modified Module03/mysite/mysite/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified Module03/mysite/mysite/__pycache__/urls.cpython-311.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions Module03/mysite/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
ALLOWED_HOSTS = []


SITE_ID = 1

# Application definition

INSTALLED_APPS = [
Expand All @@ -39,6 +41,8 @@
'django.contrib.staticfiles',
'blog.apps.BlogConfig',
'taggit',
'django.contrib.sites',
'django.contrib.sitemaps',
]

MIDDLEWARE = [
Expand Down
10 changes: 10 additions & 0 deletions Module03/mysite/mysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
from django.contrib import admin
from django.urls import path, include

from django.contrib.sitemaps.views import sitemap
from blog.sitemaps import PostSitemap

sitemaps = {
'posts': PostSitemap,
}


urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls', namespace='blog')),
path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap')

]

0 comments on commit 5b0487e

Please sign in to comment.