How to change base url or domain in sitemap - Django
So today I am going to teach you how you can change the base URL or domain name in Django sitemap. This task is pretty much easy and simple as well.
Sitemap If you don't know how to create a sitemap in Django then you can follow the following link. There I have written the whole process of creating sitemap in simple steps. So first make sure that you know how to create a sitemap in django.
Creating sitemap in Django
Changing base url in Sitemap To change the base url first you have to go into your "sitemaps.py" file. Please note that the file name may be different obviously. The important thing is, you have to just open the python file which is responsible for the sitemap generation.
Now, to change the domain/base-url we have to override get_urls() method.
You have to do something like this :
from django.contrib.sitemaps import Sitemap
from Blogs.models import blogs
from django.contrib.sites.models import Site
changefreq = "monthly"
priority = 0.5
def get_urls(self, site=None, **kwargs):
site = Site(domain='www.NewDomain.com', name='www.NewDomain.com')
return super(MyBlogSitemap, self).get_urls(site=site, **kwargs)
Here NewDomain.com is the new domain or the base url which will be used in the sitemap instead of old domain.
Some recent posts
Complete process of changing database from SQLite to MySQL - How to migrat...
" How to download a file in django | Making a large file downloadable from ...
How to use proxy in python requests | http & https proxies - Scraping...
Top Django Querysets, How to filter records | Fetching data from database e...
How to change base url or domain in sitemap - Django ...
How to Make a Website - Everything you should know about web development...
Top 5 Interview Questions : Tips for HR round ...
How to get job in IT : Perfect resume guide for IT job ...
Programming vs coding | difference between programming and coding ...
Popular PostsHow to compress image before saving to DB
Migrating from SQLite to MySQL in Django
Choosing correct M.2 SSD
How to deploy a web app on pythonanywhere
5 Steps to create sitemap in Django
How to send mails automatically in Django
Handling arguments in django urls
Media and Static configuration in Django
Language Translation & detection using python
React Js vs Angular Js
5 Tips to improve Programming Logics