Explain Django’s Request/Response Cycle.

Last updated 1 year, 10 months ago | 483 views 75     5

Tags:- Django

Django | Request/Response Cycle

Whenever a request is received by the Django server. The Request is processed by various middlewares and is passed to the URL Router. Then, the server looks for a matching URL in the urlpatterns defined for the project. If no matching URL is found, then a response with 404 Page Not Found status code is returned. If a URL matches,  then the corresponding code in the view file associated with the URL is executed to build and send a response.

The response is given in the form of HttpResponse. The response is not limited to that. The Response can be PDF, JSON, or CSV. It provides built-in support to provide responses of various types.

 

Tips and Tricks


Python In-place swapping of two numbers

 Python | In-place swapping of two numbers

>>> a, b = 10, 20
>>> print(a, b)
10 20

>>> a, b = b, a
>>> print(a, b)
20 10

 


Reversing a String in Python

Python | Reversing a String

>>> x = 'PythonWorld'
>>> print(x[: : -1])
dlroWnohtyP

 


Python join all items of a list to convert into a single string

Python | Join all items of a list to convert into a single string

>>> x = ["Python", "Online", "Training"]
>>> print(" ".join(x))
Python Online Training

 


python return multiple values from functions

Python | Return multiple values from functions

>>> def A():
	return 2, 3, 4

>>> a, b, c = A()

>>> print(a, b, c)
2 3 4

 


Python Print String N times

Python | Print String N times

>>> s = 'Python'
>>> n = 5

>>> print(s * n)
PythonPythonPythonPythonPython