0
from .forms import CommentForm

def about(request):
    title = "ola"
    #title = "Hello Stranger"
    #if request.user.is_authenticated():
       # title = "Welcome Member %s" %{request.user}
    user = request.user
    form = CommentForm(request.POST or None)
    context = {'user': user,
               'title': title,
               'form': form

              }
    if form.is_valid():
        form.save()
        #instance = form.save()
        #if not instance.name:
         #   instance.name = "robert"
        #instance.save()
        context = {
            "title": "Thanks"
        }


    templates = 'about.html'
    return render(request, templates, context)

Form code :

from django import forms 
from .models import Comment 

class CommentForm(forms.ModelForm): 
    class Meta: 
        model = Comment 
        fields = ["name", "email", "comment"] 

    def clean_email(self): 
        email = self.cleaned_data.get("email") email_base, 
        provider = email.split("@") domain, 
        extension = provider.split('.') 
        #if not "hotmail" in email: 
            # raise forms.ValidationError("Please do hotmail") 
        return email 

    def clean_name(self): 
        name = self.cleaned_data.get("name") 
        return name

I'm getting this error: AttributeError at /about/ 'CommentForm' object has no attribute 'save' Request Method: POST What I want is to see the responses from the users , meaning there data once they fill out the comment form but i get this error and do not see any of the comments in the django/admin. any help would be great thanks

Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94
robert
  • 31
  • 8
  • Can you post code of the form ? – Samuel Dauzon Sep 26 '15 at 23:06
  • Sorry but it's difficult to read. Can you edit your post for syntax highlighter and line breaks? – Samuel Dauzon Sep 26 '15 at 23:08
  • Edit it into your main post for it to be easier to see – Jeff_Hd Sep 26 '15 at 23:09
  • thanks jedema I approved your edit. Hope you all can help thanks :) – robert Sep 26 '15 at 23:30
  • still confused does anyone know why it does not work ? – robert Sep 26 '15 at 23:39
  • ?????????????????????????????????/ – robert Sep 27 '15 at 01:01
  • Can you clear the pyc files, and try again ? Also, looks like you do have syntax errors: `email = self.cleaned_data.get("email") email_base,` No need of commas at the end. Thirdly, you might want to add a check for `if request.method =="POST"` before doing `form.is_valid()` – karthikr Sep 27 '15 at 01:16
  • not sure what you mean on clear the pyc files? – robert Sep 27 '15 at 01:19
  • if i clear them will that delete my work ? – robert Sep 27 '15 at 01:24
  • If you delete the py files, you will lose your work, but if you clear the pyc files you wont. I think you need to read up on that first: http://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files – karthikr Sep 27 '15 at 01:25
  • great thanks for the link but my form still does not work still get this error: AttributeError at /about/ 'CommentForm' object has no attribute 'save' Request Method: POST – robert Sep 27 '15 at 01:31

0 Answers0