Can't save to Postgres db locally - Fresher

14 views
Skip to first unread message

Emmanuel klutse

unread,
May 15, 2019, 6:20:41 AM5/15/19
to django...@googlegroups.com
Hello Team,
I need help please, I’m try to save to my db from a FORM using the command below.
I’ve all I could but the process keeps failing and I’m stack.

File "/Users/emmanuelklutse/Documents/djangodev/myPortfolio/emmanuel/views.py", l
ine 17, in contact
c = contact(email='email',subject='subject',message='message')
TypeError: contact() got an unexpected keyword argument ‘email'


def contact(request):
if request.method == 'POST':
email = request.POST.get('email')
subject = request.POST.get('subject')
message = request.POST.get('message')

c = contact(email='email',subject='subject',message='message')
c.save()

return render (request,'emmanuel/contact.html')
else:
return render (request,'emmanuel/contact.html’)


Thanks,
Emmanuel klutse. Best regards

Chetan Ganji

unread,
May 15, 2019, 11:33:59 AM5/15/19
to django...@googlegroups.com
Problem - 
def contact(request):
      ......

      c = contact(email='email',subject='subject',message='message')
      ......

The two methods that should be doing two separate things have the same name. So, the python interpreter is confused.

Solution - 
Rename anyone of the above methods.

Regards,
Chetan Ganji
+91-900-483-4183


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/D5902281-068C-448D-8C3B-4661EC37473A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

salimon jamiu olashile

unread,
May 15, 2019, 1:40:57 PM5/15/19
to django...@googlegroups.com
You’re passing a string instead of a variable. 
c = contact(email=email,subject=subject,message=message)

Emmanuel klutse

unread,
May 15, 2019, 3:36:20 PM5/15/19
to django...@googlegroups.com
Thanks Chetan Ganji, well appreciated.

Hmmmm, I changed the method name but problem still persist.

I have tried all I can to handle the new errors but failed  again.


When I changed the contact here to contacts "c = contact(email='email',subject='subject',message='message’)"

NameError at /contact

name 'contacts' is not defined
Request Method:POST
Request URL:http://127.0.0.1:8000/contact
Django Version:2.1.1
Exception Type:NameError
Exception Value:
name 'contacts' is not defined
Exception Location:/Users/emmanuelklutse/Documents/djangodev/myPortfolio/emmanuel/views.py in contact, line 17
Python Executable:/anaconda3/envs/projectOne/bin/python
Python Version:3.5.6
Python Path:
['/Users/emmanuelklutse/Documents/djangodev/myPortfolio',
 '/anaconda3/envs/projectOne/lib/python35.zip',
 '/anaconda3/envs/projectOne/lib/python3.5',
 '/anaconda3/envs/projectOne/lib/python3.5/plat-darwin',
 '/anaconda3/envs/projectOne/lib/python3.5/lib-dynload',
 '/anaconda3/envs/projectOne/lib/python3.5/site-packages']
Server time:Wed, 15 May 2019 19:20:31 +0000

When I changed the contact in the function contacts “ def contacts(request)"  


AttributeError at /contact

'contact' object has no attribute 'get'
Request Method:GET
Request URL:http://127.0.0.1:8000/contact
Django Version:2.1.1
Exception Type:AttributeError
Exception Value:
'contact' object has no attribute 'get'
Exception Location:/anaconda3/envs/projectOne/lib/python3.5/site-packages/django/middleware/clickjacking.py in process_response, line 26
Python Executable:/anaconda3/envs/projectOne/bin/python
Python Version:3.5.6
Python Path:
['/Users/emmanuelklutse/Documents/djangodev/myPortfolio',
 '/anaconda3/envs/projectOne/lib/python35.zip',
 '/anaconda3/envs/projectOne/lib/python3.5',
 '/anaconda3/envs/projectOne/lib/python3.5/plat-darwin',
 '/anaconda3/envs/projectOne/lib/python3.5/lib-dynload',
 '/anaconda3/envs/projectOne/lib/python3.5/site-packages']
Server time:Wed, 15 May 2019 19:30:00 +0000

salimon jamiu olashile

unread,
May 16, 2019, 9:13:20 AM5/16/19
to django...@googlegroups.com
Is “contact” a model?


salimon jamiu olashile

unread,
May 16, 2019, 9:13:56 AM5/16/19
to django...@googlegroups.com
Hello,

From what I see contact is a model & you want to create a new contact. So, instead of this;

c = contact(email='email',subject=‘
subject',message='message')
 c.save()

just do this;

c = contact.objects.create(email=email, subject=subject, message=message)

Regards 

Emmanuel klutse

unread,
May 16, 2019, 6:01:11 PM5/16/19
to django...@googlegroups.com
Thanks,
I tried your approach but it failed again.
I will start all over with a different approach. 
I will update you if I find a way out. 

Reply all
Reply to author
Forward
0 new messages