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)
You need to import render
from django.shortcuts
as it is not a built-in function.:
from django.shortcuts import render
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With