0

happy new year everyone...I am new to django and i am working on a project a resume page i need help with the contact me section, i want to do something i seen in a video https://www.youtube.com/watch?v=w4ilq6Zk-08. The book i used to learn only uses class to view templates. below is my code

from django.views.generic import TemplateView
from django.shortcuts import render
# Create your views here.
class ProfilePageView(TemplateView):
    template_name = 'femi_profile.html'

    def contact(request):
        if request.method == "POST":
            name = request.POST['name']
            email = request.POST['email']
            subject = request.POST['subject']
            message = request.POST['message']

            return render(request, 'femi_profile.html', {'contact_name': name})

        else:
            return render(request, 'femi_profile.html', {})
femiir
  • 190
  • 1
  • 2
  • 15

1 Answers1

0

After reading the django documentation https://docs.djangoproject.com/en/3.1/topics/class-based-views/intro/ once more and trying different lines of code i finally got that run and i am not asking why is it runing? i figured out how to go about this.

find the correct code below

from django.views.generic import TemplateView
from django.shortcuts import render
# Create your views here.

class ProfilePageView(TemplateView):
    template_name = 'femi_profile.html'

    def get(self, request, *args, **kwargs):
        return render(request, self.template_name, {})

    def post(self, request, *args, **kwargs):
        if request.method == "POST":
            name = request.POST['name']
            email = request.POST['email']
            subject = request.POST['subject']
            message = request.POST['message']

            return render(request, self.template_name, {'contact_name': name})
femiir
  • 190
  • 1
  • 2
  • 15