-->

Software engineering facts, information, and skills categorized as Django

HttpRequest methods

Priya Philip 3 months, 2 weeks ago
HttpRequest represents an incoming HTTP request, including all HTTP headers and user-submitted data

HttpRequest attributes

Priya Philip 3 months, 2 weeks ago

Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function. Each view is responsible for returning an HttpResponse object.

Infinite iterators in Python

Priya Philip 3 months, 3 weeks ago

An object representing a stream of data. Repeated calls to the iterator’s __next__() method (or passing it to the built-in functionnext()) return successive items in the stream. When no more data are available a StopIteration exception is raised instead. At this point, the iterator object is exhausted and any further calls to its __next__() method just raise StopIteration again. Iterators are required to have an __iter__() method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes. A container object (such as a list) produces a fresh new iterator each time you pass it to the iter() function or use it in a for loop. Attempting this with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container.

__str__ vs __repr__ in Python

Priya Philip 4 months ago

Both __repr__ and __str__ are used to represent objects in different ways.The default implementation of __repr__ for a str value can be called as an argument to eval, and the return value would be a valid string object.

Difference between null=True, blank=True in django

Priya Philip 1 year, 7 months ago

The main differnce for null and blank is 

What is @permalink and get_absolute_url in Django?

Varghese Chacko 1 year, 8 months ago

What is @permalink and get_absolute_url in Django? When and why to use it?

Configure Amazon S3 for Mezzanine - a Django Blog engine

Varghese Chacko 1 year, 8 months ago

Amazon S3 is an efficient static file storage system for its services and relatively cheap. On the other hand Django is a nice web development framework that doesn't like to handle static files. Mezzanine is a popular blog engine  built in Django. Since Django doesn't like to handle static files on production systems, we always have to configure a web server like nginx or apache webserver to serve static files. On the other hand, its easy to host static files to Amazon S3. The S3 configuration for static files is easy, but saving user uploaded files for Django web app may raise some permission issues. Here is how we have configured the Django-S3-Mezzanine blog.

Create sitemap using Django sitemap framework

Varghese Chacko 1 year, 8 months ago

The django sitemap framework is very flexible. We can use it to create sitemap for any item in thedatabase, along with custom configurations. The very basic step is to add django.contrib.sitemaps to the installed apps. Then it is better to have our own sitemaps.py. In the sitemaps.py, we have to create a class by inheriting the class Sitemap from django.contrib.sitemaps. In this class we can define our properties for entries in the sitemap.

Create sitemap for static pages in Django application

Varghese Chacko 1 year, 8 months ago

We have both static and dynamic pages in a Djangoapplication. How will we add static pages to stitemap? It is very siple. As first step, we have to include 'django.contrib.sitemaps' to the installed apps.

Wish to hire us?

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.