In this article we will discuss how to upload an Excel file and then process the content without storing file on server. One approach could be uploading the file, storing it in upload directory and then reading the file. Another approach could be uploading file and reading it directly from post data without storing it in memory and displaying the data.
We will work with the later approach here.
You may create a new project or work on existing code.
If you are setting up a new project then create a new virtual environment and install Django 2.0 and openpyxl modules in virtual environment using pip.
A site map is a list of a website’s content designed to help both users and search engines navigate the site. A site map can be a hierarchical list of pages, an organization chart, or an XML document that provides instructions to search engine crawl bots.
Why sitemaps is required:
XML Sitemaps are important for SEO because they make it easier for Google to find your site’s pages—this is important because Google ranks web PAGES not just websites. There is no downside of having an XML Sitemap and having one can improve your SEO, so we highly recommend them.
Create two different classes in sitemap.py file, one for static pages and another for Dynamic URLs.
Lets assume your website sell some product where product details are stored in database. Once a new product is added to database, you want that product page to be searchable by search engines. We need to add all such product pages/urls to sitemaps.
Define a class
StaticSitemap in your
sitemap.py file. Define the mandatory function
items in it which will return the list of objects. These objects will be passed to location method which will create URL from these objects.
Here in items function, we are returning
appname:url_name which will be used by location method to convert into absolute URL. Refer you app’s urls.py file for url names.
Similarly we will create Dynamic sitemap by fetching values from DB.
In software engineering, don’t repeat yourself (DRY) is a principle of software development aimed at reducing repetition of code. All the installed packages and apps we use in our Python/Django projects are great example of DRY concept.
In this article we will learn:
– How to create custom middleware in Django project.
– How to create reusable Django App / Python Package to block the IPs.
– How to upload the python package on pypi and djangopackages.org.