django domain name 1

django domain name

from django.shortcuts import render

def my_view(request):
    return render(request, 'my_template.html', context)

Here is what the above code is Doing:
1. The render() function takes the request object as its first argument, a template name as its second argument and a dictionary as its optional third argument. It returns an HttpResponse object of the given template rendered with the given context.
2. The render() function takes care of returning the HttpResponse object with the correct content-type for you.
3. The render() function takes an optional third argument that should be a dictionary of values to add to the template context. For example, if you want to add a list of friends to the context, you would do this:

def my_view(request):

return render(request, ‘my_template.html’, {‘friends’: [‘john’, ‘pat’, ‘gary’, ‘michael’]})

Similar Posts