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

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

Asterisk AGI Python Script to Dialplan does not work -