DjangoとPythonを使用して挿入ページを開いているときにエラーが発生します。私は以下のエラーを説明しています。DjangoとPythonを使用してページを挿入しようとするとエラーが発生する
TypeError at /insert/
context must be a dict rather than WSGIRequest.
Request Method: GET
Request URL: http://127.0.0.1:8000/insert/
Django Version: 1.11.2
Exception Type: TypeError
Exception Value:
context must be a dict rather than WSGIRequest.
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/context.py in make_context, line 287
Python Executable: /usr/bin/python
Python Version: 2.7.6
私は以下のコードを説明しています。
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader,Context,RequestContext
from crud.models import Person
# Create your views here.
def index(request):
t = loader.get_template('index.html')
#c = Context({'message': 'Hello world!'})
return HttpResponse(t.render({'message': 'Hello world!'}))
def insert(request):
# If this is a post request we insert the person
if request.method == 'POST':
p = Person(
name=request.POST['name'],
phone=request.POST['phone'],
age=request.POST['age']
)
p.save()
t = loader.get_template('insert.html')
#c = RequestContext(request)
return HttpResponse(t.render(request))
私はDjango 1.11
を使用しています。この問題を解決するのを手伝ってください。
なぜあなたは要求をレンダリングしようとしていますか?あなたのテンプレートのデータを含むdict(コンテキスト)が必要です。 – vZ10