No, I meant like this:

def Contact(request):
    if request.method == 'POST':
        form = ContactUsForm(request.POST)
        if form.is_valid():
            form.save()
            context = {'form': form}

            return redirect('contactus.html')
    else:
        form = ContactUsForm()

    return render(request,  'contactus.html', {'form': form})


Also - the redirect should go to a valid django route - What is the route
that you want to redirect to after a successful posting?

Another thing you should also look into is using class based views instead
of function based views, because then you don't need to write as much code
- but get this working first! :-)

Regards,

Andréas


Den mån 12 nov. 2018 kl 15:38 skrev Tosin Ayoola <tosinayoo...@gmail.com>:

> you mean i should have it like this
> def Contact(request):
>     if request.method == 'POST':
>         form = ContactUsForm(request.POST)
>         if form.is_valid():
>             form.save()
>             context = {'form': form}
>
>             return redirect('contactus.html')
>
>
>
>     else:
>         form = ContactUsForm()
>         return( 'contactus.html', ) or .....
>
>
> On Mon, Nov 12, 2018 at 3:31 PM Andréas Kühne <andreas.ku...@hypercode.se>
> wrote:
>
>> Just move the return render part from the get request path to always
>> return. That way you will get the form with the correct information when
>> the form isn't valid.
>>
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den mån 12 nov. 2018 kl 15:20 skrev Tosin Ayoola <tosinayoo...@gmail.com
>> >:
>>
>>> yes the form is valid and the issue is the form doesn't display any
>>> error if the required field are not filled
>>> even when i use just the form = ContactUsForm(request.POST), it still
>>> doesn't work
>>> as for the third wat do you suggest i do ?
>>>
>>> On Mon, Nov 12, 2018 at 3:06 PM Andréas Kühne <
>>> andreas.ku...@hypercode.se> wrote:
>>>
>>>> Hi,
>>>>
>>>> First of all - are you sure that the form is valid? You don't show the
>>>> ContactUs model, but I'm guessing that all fields are required? Are they
>>>> all filled in?
>>>> Second - in the contact method you first check if it is a POST and then
>>>> populate with: form = ContactUsForm(request.POST or None).
>>>> The "or None" part won't do anything - it will never be called.
>>>> Finally - if the form ISN'T valid - the user won't get any response at
>>>> all? It'll just go to en empty page?
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>>
>>>> Den mån 12 nov. 2018 kl 14:31 skrev Tosin Ayoola <
>>>> tosinayoo...@gmail.com>:
>>>>
>>>>> halo,
>>>>> working on a contact us form to receive information from the user but
>>>>> my issue is the data doesn't get save to the database and i'm not getting
>>>>> any error message can anyone help out
>>>>> below is my view an forms.py
>>>>>
>>>>> --
>>>>> 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+unsubscr...@googlegroups.com.
>>>>> To post to this group, send email to django-users@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/CAHLKn70gTCa98GpXiYfm1kJqqQZHYiaYz4U39ocBCuGa4n-3Lw%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/django-users/CAHLKn70gTCa98GpXiYfm1kJqqQZHYiaYz4U39ocBCuGa4n-3Lw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>>> 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+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@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/CAK4qSCfjemsyhhfOiDEB1oXFrPL47ixb_Vvq2624Pwv1ddBeuw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAK4qSCfjemsyhhfOiDEB1oXFrPL47ixb_Vvq2624Pwv1ddBeuw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> 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+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@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/CAK4qSCcSp_L%2BNpHCqM4Yf04%2Byftm9t_DBXe05grHEGMTgrrv4w%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAK4qSCcSp_L%2BNpHCqM4Yf04%2Byftm9t_DBXe05grHEGMTgrrv4w%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAK4qSCcJ%3DPEo1kOuK83Nts1cQnKhA6y3jVyYG329wgPE-ZtTkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to