0

I just finished and deployed my first Django app with pythonanywhere, but I did not know that a sitemap was required. I really wouldn't like doing all the steps in my IDE and then start the deployment process again. Is there a way to implement it at this stage? Sounds intuitive to create the sitemap.XML from https://www.xml-sitemaps.com/ and add it as a new view. Would that work for my app to become indexed in the search engines?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Sep
  • 31
  • 2
  • 2
    Django has its own framework to [generate sitemap](https://docs.djangoproject.com/en/3.0/ref/contrib/sitemaps/). I don't see a reason to generate it manually. Anyway, you will need to add URL config to your `urls.py` file. I've never used pythonanywhere but it seems they don't have any gateway like Nginx to set up, for example, path to your manually generated sitemap. So you will have to modify the code of `urls.py` anyway. And to manage your site indexing by search engines you will need to add it to [search consoles](https://search.google.com/search-console/about). Hope that helps. – salvicode Jul 17 '20 at 03:50
  • Thanks. Yeah, I should have used the framework, but at this stage that implies a lot of work. I can create a myapp.com/sitemapp.xml by just adding some code from pythonanywhere, but I don't know if it's possible to create an xml with html and whether it would work for the crawlers. – Sep Jul 17 '20 at 04:04
  • Probably you could generate it manually and then using [template customization](https://docs.djangoproject.com/en/3.0/ref/contrib/sitemaps/#template-customization) create your own template with your manually generated content and ignore Django stuff but it looks like a hack rather than a solution. – salvicode Jul 17 '20 at 04:13
  • If you generate the sitemap using Django, you could set up a static file mapping on PythonAnywhere to serve it -- that would be equivalent to the nginx config that @salivicode mentioned. – Giles Thomas Jul 17 '20 at 14:54
  • Not to be stubborn, but let's assume that I use an online sitemap generating toll and convert the xml to html. Then create a view so that typing mysite.com/sitemap.xml renders a sitemap with all the norms. Of course, it would just be plain html but the displayed text would be the sitemap. Why wouldn't that work? – Sep Jul 17 '20 at 15:59
  • I reckon it probably would; you could make it even better by setting the MIME type for the response in your Django view be `application/xml`, which is the correct type for a sitemap. – Giles Thomas Jul 20 '20 at 10:33
  • Yes that works! It was a way simpler solution for a sitemap that won't need to change and the app is already found in google and Bing. thanks – Sep Jul 20 '20 at 17:42

0 Answers0