Hello!
I've tried uploading the data I'm entering in the webpage to the database,
but the data is not entering. Since I am new to django, I don't know what
the error is. Can anyone please help me? I am using Mysql database.
*My views.py:*
*from django.views.generic import FormView, TemplateView*
*from .forms import EmailForm*
*from django.urls import reverse_lazy*
*from mailapp.models import Email*
*from django.shortcuts import render*
*class MailView(FormView):*
* template_name = 'index.html'*
* form_class = EmailForm*
* success_url = reverse_lazy('mailapp:success')*
* def form_valid(self, form):*
* # Calls the custom send method*
* form.send()*
* return super().form_valid(form)*
* def registered(request):*
* if request.method == 'POST':*
* if request.POST.get('name') and request.POST.get('email') and
request.POST.get('inquiry') and request.POST.get('message'):*
* mail = Email()*
* mail.name = request.POST.get('name')*
* mail.email = request.POST.get('email')*
* mail.inquiry = request.POST.get('inquiry')*
* mail.message = request.POST.get('message')*
* mail.save() *
* return render(request, 'success.html')*
* else:*
* return render(request, 'success.html')*
*class MailSuccessView(TemplateView):*
* template_name = 'success.html'*
*models.py*
*from django.db import models*
*from django.contrib.auth.models import User*
*class Email(models.Model):*
* name = models.CharField(max_length=120)*
* email = models.EmailField()*
* inquiry = models.CharField(max_length=70)*
* message = models.CharField(max_length=300)*
* def __str__(self):*
* return self.name*
*admin.py*
*from django.contrib import admin*
*from .models import Email*
*admin.site.register(Email)*
Thank you in advance!!
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/a4c11360-6516-4d3e-8e82-f42adc70587en%40googlegroups.com.