“ AttributeError:'tuple'对象在Django应用程序上没有属性'get'”

时间:2019-12-23 10:25:12

标签: python django django-models django-forms django-views

我无法在Django应用程序中找出错误的出处。

内部服务器错误:/ app / register / 追溯(最近一次通话):   文件“ /home/stokesy/Desktop/MyDjangoEnv/lib/python3.7/site-packages/django/core/handlers/exception.py”,第34行,位于内部     响应= get_response(请求)   调用中的文件“ /home/stokesy/Desktop/MyDjangoEnv/lib/python3.7/site-packages/django/utils/deprecation.py”,第96行     响应= self.process_response(请求,响应)   在process_response中,文件“ /home/stokesy/Desktop/MyDjangoEnv/lib/python3.7/site-packages/django/middleware/clickjacking.py”,第26行     如果response.get('X-Frame-Options')不是None: AttributeError:“ tuple”对象没有属性“ get”`

views.py:

from django.shortcuts import render
from basic_app.forms import UserProfileInfoForm,UserForm

# Create your views here.
def index(request):
       return render(request,'basic_app/index.html')

def register(request):

       registered = False

       if request.method == "POST" :
              user_form = UserForm(data=request.POST)
              profile_form = UserProfileInfoForm(data=request.POST)


          if user_form.is_valid() and profile_form.is_valid():
                 user = user_form.save()
                 user.set_password(user.password)
                 user.save()

                 profile = profile_form.save(commit=False)
                 profile.user = user

                 if 'profile_pic' in request.FILES :
                        profile.profile_pic = request.FILES['profile_pic']

                 profile.save()

                 registered = True

          else :
                 print(user_form.errors,profile_form.errors)

   else:
          user_form = UserForm()
          profile_form = UserProfileInfoForm()

   return render(request,'basic_app/registration.html'),{'user_form':user_form,'profile_form':profile_form,'registered':registered}

1 个答案:

答案 0 :(得分:1)

您做错了。您在字典前关闭了渲染括号。

head -nx         # consider first x lines from file or stdin
tail -nx         # consider last x lines from file or stdin
grep -mx         # select max. x matches
tac | ... | tac  # read file from end (better performance for big files)

您已经这样做

return render(request,'basic_app/registration.html'),{'user_form':user_form,'profile_form':profile_form,'registered':registered}

不要在字典后关闭,因为字典是第三个参数。