Answer the question
In order to leave comments, you need to log in
How to correctly render the page after a post request in the Django3 View class?
views.py:
from django.shortcuts import render, redirect
from django.views import View
from .models import HeaderTextDesc, Contacts, Portfolio
from Services.models import Services
from Applications.forms import ApplicationsForm
class MainView(View):
def post(self, req):
form = ApplicationsForm(req.POST)
if form.is_valid():
form.save()
return redirect('/')
def get(self, req):
headerTextDesc, contacts = HeaderTextDesc.objects.all()[0], Contacts.objects.all()[0]
services_objects = Services.objects.all()
potrfolio_objects = Portfolio.objects.all()
form = ApplicationsForm()
context = {
'title': headerTextDesc.title,
'desc': headerTextDesc.description,
'tel_number': contacts.tel_number,
'vk_link': contacts.vk_link,
'telegram_link': contacts.telegram_link,
'whatsApp_link': contacts.whatsApp_link,
'services_objects': services_objects,
'portfolio_objects': potrfolio_objects,
'form': form
}
return render(req, 'MainTEST.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question