python - Django - using a form from another app - issue creating a redirect -
i have contact app in project. use contact form app in home page created in views.py:
from django.views import generic contact.forms import contactform class homepage(generic.templateview): template_name = "home.html" def get_context_data(self, *args, **kwargs): context=super(homepage, self).get_context_data(*args, **kwargs) context['form'] = contactform return context
when submit form on home page redirects blank page, instead of either home page, or thank page.
here definition in views.py of contact app:
def contact(request): form_class = contactform if request.method == 'post': form = form_class(data=request.post) if form.is_valid(): contact_name = request.post.get('contact_name', '') contact_email = request.post.get('contact_email', '') form_content = request.post.get('content', '') template = get_template('contact/contact_template.txt') context = dict({'contact_name': contact_name, 'contact_email': contact_email, 'form_content': form_content,}) content = template.render(context) email = emailmessage( "new contact form submission", content, "your website" +'', ['you@company.com'], headers = {'reply-to': contact_email } ) email.send() return render(request, 'contact/thank_you.html') return render(request, 'contact/contact.html', { 'form': form_class, })
i noticed filling form , hitting submit not output console contact app page, nor confirmation page. believe means need give form path files, or copy files main templates directory, , tell view find them. being new @ django - i'm totally lost. got far creating creating view, i'm struggling. help!
action="contact/"
or action="{% url contact:contact %}"
form in home.html , here url resovle doc.
you can simplify code class based view formview or createview
from django.views.generic import formview, createview
wiki
Comments
Post a Comment