Not sure whats going on. I added a contact form to a website(it works) but when i tied it to my base.html i noticed that my menu isnt working (#global variable) on this particular site (html looks like there is no menu at all, just div surrounding it). It buggs only in contact_form.html which contains my form. Any idea why would this happen?
forms.py
class ContactForm(forms.Form):
name = forms.CharField(required=False, label='Your name')
email = forms.EmailField(label='E-mail address')
subject = forms.CharField(label='Subject')
phone = forms.CharField(required=False, label='Phone number')
message = forms.CharField(label='Your message')
views.py
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
message = cd['message']
# construct the message body from the form's cleaned data
body = """\
from: %s
name: %s
phone: %s
message: %s""" % (cd['email'], cd['name'], cd['phone'], cd['message'])
send_mail(
cd['subject'], #subject is here
body, #here is the message
settings.DEFAULT_FROM_EMAIL, # from
[settings.DEFAULT_FROM_EMAIL] # to
)
return HttpResponseRedirect('/contact/thanks/')
else:
form = ContactForm()
csrf_form = {'form': form}
csrf_form.update(csrf(request))
return render_to_response('contact_form.html',csrf_form)
aganders3 was right.
i think i found my solution here: https://docs.djangoproject.com/en/dev/ref/templates/api/
fixed the code above so it looks like:
Everything works as it supposed to now.