Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Python: global name 'render' is not defined

I am getting an error in my Django project, and it looks like it's coming from my views.py file:

from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
import datetime

def get_date_time(request):
    now = datetime.datetime.now()
    return render(request, 'date_time.html', {'current_date': now})

Error: global name 'render' is not defined

What can I do to solve this?

EDIT

Solution:

t = get_template('document.html')
html = t.render(Context({'variable': value}))
return HttpResponse(html)
like image 923
TheProofIsTrivium Avatar asked Jul 28 '13 07:07

TheProofIsTrivium


1 Answers

You need to import render from django.shortcuts as it is not a built-in function.:

from django.shortcuts import render
like image 161
Ashwini Chaudhary Avatar answered Sep 18 '22 17:09

Ashwini Chaudhary