我正在使用Python 3.6,并且我想在Django框架中的PyCharm中运行一个项目,但出现此错误:
TypeError at /
render() got an unexpected keyword argument 'context_instance'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.1.7
Exception Type: TypeError
Exception Value:
render() got an unexpected keyword argument 'context_instance'
Exception Location: C:\Users\hp\AppData\Local\Programs\Python\Python36\dj\xaon\app\views.py in home, line 16
Python Executable: C:\Users\hp\AppData\Local\Programs\Python\Python36\dj\f\Scripts\python.exe
Python Version: 3.6.5
Python Path:
['C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\xaon',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f\\Scripts\\python36.zip',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f\\DLLs',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f\\lib',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f\\Scripts',
'c:\\users\\hp\\appdata\\local\\programs\\python\\python36\\Lib',
'c:\\users\\hp\\appdata\\local\\programs\\python\\python36\\DLLs',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f',
'C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python36\\dj\\f\\lib\\site-packages']
Server time: Thu, 28 Mar 2019 22:20:33 +0000
我的view.py
如下:
def home(request):
assert isinstance(request, HttpRequest)
return render(
request,
'app/index.html',
context_instance=RequestContext(request, { 'title':'Home Page', })
)
答案 0 :(得分:1)
您使用的是Django 2.1.7,但context_instance
的位置参数为deprecated since version 1.8,并在Django 2.0中被删除。您只需在调用render()
快捷键功能时使用use context
instead。
有关context_instance
的更多信息,请参见this other Stack Overflow post。