Привет! Я пытаюсь заставить свою ModelForm отправлять сообщения в мою базу данных, чтобы я мог видеть, действительно ли пользователи зарегистрированы в моей базе данных, называется представление для регистрации (Registernow).Фактическая база данных отображается в admin.py, но когда я ввожу информацию в мой ModelForm, созданный Django, он не будет отправлять POST в базу данных, поэтому я не увижу зарегистрированных пользователей под моей ModelForm в admin.py, не могли бы вы мне помочь?
VIEWS.PY
from django.shortcuts import render
from App1 import forms
from App1.forms import LogInForm, SignedUpForm
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
# Create your views here.
def index(request):
form = LogInForm()
if request.method == 'POST':
emailview = request.POST.get('email')
passwordview = request.POST.get('password')
varauth = authenticate(username=emailview, password=passwordview)
if varauth:
if varauth.is_active:
login(request, varauth)
request.varauth
return HttpResponseRedirect(reverse('index'))
else:
return HttpResponse("Account Not Active")
else:
print("Someone tried to log in and failed")
print('Username: {}\nPassword: {} '.format(emailview, passwordview))
return render(request, 'App1/index.html', {'form': form})
@login_required
def special(request):
return HttpResponse("YOU ARE LOGGED IN")
@login_required
def activeuserlogout(request):
logout(request)
return HttpResponseRedirect(reverse('index'))
def terms_and_conditions(request):
return render(request, 'App1/termsandconditions.html')
# LAST EDITED CHANGE IN THE POST GET PARAMETER
def Registernow(request):
form2 = SignedUpForm()
if request.method == 'POST':
form2 = SignedUpForm(request.POST)
if form2.is_valid():
instance = form2.save(commit=False)
else:
form2 = SignedUpForm()
HttpResponseRedirect(reverse('index'))
return render(request, 'App1/register_now.html', {'form2' : form2})
def main_face(request):
return render(request, 'App1/mainface.html')
END VIEWS.PY
*********************************************************************
FORMS.PY
from django import forms
from django.forms import ModelForm
from App1.models import LogInModel, SignedUpModel
# LOG IN MODELFORM
class LogInForm(ModelForm):
email = forms.EmailField(label='', widget=forms.EmailInput(attrs=
{'placeholder': 'example@gmail.com'}))
password = forms.CharField(label='', widget=forms.PasswordInput(attrs=
{'placeholder': 'password'}))
class Meta:
model = LogInModel
fields = {'email', 'password',}
class Media:
css = {
'__all__': 'style_sheet_signin.css'
}
# END MODELFORM
class SignedUpForm(ModelForm):
name = forms.CharField(label='Name', widget=forms.TextInput(attrs=
{'placeholder' : 'First Name'}))
lastname = forms.CharField(label='Last Name', widget=forms.TextInput(attrs=
{'placeholder' : 'Last Name'}))
email2 = forms.EmailField(label='Email', widget=forms.EmailInput(attrs=
{'placeholder' : 'example34@gmail.com'}))
password2 = forms.CharField(label='Password', widget=forms.PasswordInput(attrs=
{'placeholder' : 'Password'}))
passconf = forms.CharField(label='Confirm Password', widget=forms.PasswordInput(attrs=
{'placeholder' : 'Confirm'}))
phone_num = forms.IntegerField(label='Phone Number', widget=forms.TextInput(attrs=
{'placeholder' : 'eg. 5196329087'}))
class Meta:
model = SignedUpModel
fields = {'name', 'lastname',
'email2', 'password2', 'passconf', 'phone_num',}
class Media:
css = {
'__all__': ('registrationbonky.css')
}
# END MODELFORM
END FORMS.PY
******************************************************************
MODELS.PY
from django.db import models
# LOGIN MODEL AND MODELFORM HERE
class LogInModel(models.Model):
email = models.EmailField()
password = models.CharField(max_length=256)
# END MODEL
# SIGNIN IN MODEL
class SignedUpModel(models.Model):
name = models.CharField(max_length=256)
lastname = models.CharField(max_length=256)
email2 = models.EmailField()
password2 = models.CharField(max_length=256)
passconf = models.CharField(max_length=256)
phone_num = models.CharField(max_length=20)
# END MODEL
END MODELS.PY
*******************************************************************
HTML REGISTRATION PAGE FORM
<form class="" action="{% url 'App1:index' %}" method="POST">
<h3 id='rege'>REGISTRATION</h3>
<br>
{% csrf_token %}
{{form2.as_table}}
<br>
<input id='regebtn' type="submit" name="" value="REGISTER">
</form>
***************************************************************
***************************************************************