Django Python: global name "render" not defined

I am getting an error in my Django project, and it looks like this comes from the 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 problem?

EDIT

Decision:

 t = get_template('document.html') html = t.render(Context({'variable': value})) return HttpResponse(html) 
+4
source share
2 answers

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

 from django.shortcuts import render 
+12
source

If you follow the Django tutorial and have this error, but already have the import, it may be because the web server needs to be rebooted. Code changes will not be displayed until runserver is started again.

0
source

Source: https://habr.com/ru/post/1493896/


All Articles