Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object has no attribute 'get' -Django 1.8 #12

Open
talhaobject90 opened this issue May 29, 2015 · 6 comments
Open

Object has no attribute 'get' -Django 1.8 #12

talhaobject90 opened this issue May 29, 2015 · 6 comments

Comments

@talhaobject90
Copy link

I am using Django 1.8 version, don't know whether it's a version related problem. But after adding all code in respective forms.py, views.py, and test_template.py, It returns

testForm' object has no attribute 'get'

I think i might missed to add the appname in settings.py apps.
i tried the default name but it didn't worked , it's not pointed in you repo readme too.
Here is the output,

Request Method: GET
Request URL: http://framework.com/test_template/

Django Version: 1.8.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'framework')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1.             response = middleware_method(request, response)
    
    File "/usr/local/lib/python2.7/dist-packages/django/middleware/clickjacking.py" in process_response
  2.     if response.get('X-Frame-Options', None) is not None:
    

Exception Type: AttributeError at /test_template/
Exception Value: 'testForm' object has no attribute 'get'

screenshot from 2015-05-29 21 59 07

I had reached here using this ,
http://stackoverflow.com/a/16650451/4190386
and found it as the best way to implement my json form.

Could you please look into it?

@adithyadinesh96
Copy link

Even i got same error did you find any solution ?

@abbasovalex
Copy link
Owner

@adithyadinesh96 hi! Can you show/share your code? Currently, I am seeing problem into process_response into the middleware "clickjacking.py".

@adithyadinesh96
Copy link

adithyadinesh96 commented Feb 5, 2018

Any response from Django i am getting this error if response.get('X-Frame-Options', None) is not None:
AttributeError: 'int' object has no attribute 'get' . In previous Django versions this wasnt the problem but after i upgraded to Django 1.8 getting this error

@abbasovalex
Copy link
Owner

@adithyadinesh96 It seems that you need investigate why your response is int

@rajmasud
Copy link

rajmasud commented Jul 24, 2019

I was getting the same error too but in my case, I was calling the "form class" itself instead of calling the "view" function from the urls.py. See the code below:

forms.py:

class TestForm(forms.Form):
    test = forms.CharField(label='Name', max_length=100)

views.py:

def FormView(request):
    frm = TestForm()

    context = {'frm': frm}
    return render(request, 'formtest.html', context)

urls.py:
I had:

urlpatterns = [
    path('formtest/', views.TestForm, name='Form_Test'),
]

What I should have:

urlpatterns = [
    path('formtest/', views.FormView, name='Form_Test'),
]

if you are using an IDE, you will get both the options since you have imported the forms.py in the views. py and it's easy to pick the other one.

@arbkm22
Copy link

arbkm22 commented Oct 12, 2020

I resolved this by changing the urls.py, I was calling the class NameForm instead of the function defined in views.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants