yon*_*ano 7 python django render
我的Django项目中出现错误,看起来它来自我的views.py文件:
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})
Run Code Online (Sandbox Code Playgroud)
错误: global name 'render' is not defined
我该怎么做才能解决这个问题?
编辑
解:
t = get_template('document.html')
html = t.render(Context({'variable': value}))
return HttpResponse(html)
Run Code Online (Sandbox Code Playgroud)
Ash*_*ary 17
您需要导入render,django.shortcuts因为它不是内置函数:
from django.shortcuts import render
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13550 次 |
| 最近记录: |