Answer the question
In order to leave comments, you need to log in
Why is django form not displaying?
Why is django form not displaying?
Here is the forms.py file:
from django import forms
from django.forms import ModelForm
from .models import User
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = ['name_user', 'email_user', 'password']
from django.db import models
import datetime
from django.utils import timezone
# Create your models here.
class Trailer(models.Model):
name_trailer = models.CharField("Название трейлера", max_length=200)
pub_date = models.DateTimeField('Дата публикации трейлера', default=timezone.now())
trailer = models.FileField(upload_to='videos/', null=True, verbose_name="")
class User(models.Model):
name_user = models.CharField("Name", max_length=50)
email_user = models.EmailField('Email')
password = models.CharField('Password', max_length=50)
data_create_user = models.DateTimeField('Account creation date', default=timezone.now())
from django.shortcuts import render
from .forms import UserForm
from django.contrib.auth import authenticate, login
def index(request):
return render(request, 'polls/index.html')
def trailers(request):
return render(request, 'polls/trailers.html')
def about(request):
return render(request, 'polls/about.html')
def login(request):
return render(request, 'polls/login.html')
def registration(request):
return render(request, 'polls/registration.html')
def post_new(request):
form = UserForm()
data = {
'form': form
}
return render(request, 'polls/registration.html', data)
<div class="registration_form">
<h1>Регистрация</h1>
<form class="form_registration" method="post">
{% csrf_token %}
{{ form.as_ul }}
<label>Введите ваше имя пользователя:</label><br>
<input name="user_user" id="user_username" placeholder="Ваше имя" value="{{ current_name }}" required><br>
<label>Введите вашу почту:</label><br>
<input name="user_email" type="email" id="user_email" placeholder="Ваша почта" value="{{ current_email }}" required><br>
<label>Введите ваш пароль:</label><br>
<input name="user_pass" type="password" id="user_pass" placeholder="Ваш пароль" required><br>
<input name="user_submit" type="submit" id="user_submit" value="Зарегистрироваться">
</form>
</div>
Answer the question
In order to leave comments, you need to log in
At a minimum, you should not define the user model in this way. The User model is already present in Django. The fields that you defined for the user are already there, so I advise you to use the built-in authentication system. You can read about it here - Documentation .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question