Why form with the ImageField is not valid in DJango? - python

I have model in Django which name is "User":
class User(models.Model):
user_id = models.AutoField(auto_created = True, primary_key = True, serialize = False, verbose_name ='ID')
surname = models.CharField(max_length=100)
name = models.CharField(max_length=100)
patronymic = models.CharField(max_length=100)
email = models.CharField(max_length=100)
avatar = models.ImageField(upload_to='store/static/store/user_avatars/')
Also I include columns of this model into my form:
class UserForm(forms.Form):
surname = forms.CharField(max_length=100)
name = forms.CharField(max_length=100)
patronymic = forms.CharField(max_length=100)
email = forms.CharField(max_length=100)
password = forms.CharField(max_length=100)
avatar = forms.ImageField()
View which gets that data:
def sign_up(request):
if request.method == 'GET':
return render(request, 'store/sign_up.html')
elif request.method == 'POST':
form = UserForm(request.POST, request.FILES)
if form.is_valid():
user = User(surname=form.cleaned_data['surname'],
name=form.cleaned_data['name'],
patronymic=form.cleaned_data['patronymic'],
email=form.cleaned_data['email'],
avatar=form.cleaned_data['avatar'])
user.save()
return HttpResponse("Alright, you signed up! " + form.cleaned_data['email'])
else:
print(form.as_table())
return HttpResponse("Data is error!")
And, finally, front of this view:
<form method="post">
{% csrf_token %}
<div class="user_data">
<div class="user_data_grid">
<input type="text" name="surname" placeholder="Surname" id="surname" style="grid-row: 2 / span 1">
<input type="text" name="name" placeholder="Name" id="name" style="grid-row: 3 / span 1">
<input type="text" name="patronymic" placeholder="Patronymic" id="patronymic" style="grid-row: 4 / span 1">
<input type="email" name="email" placeholder="Enter your mail" id="email" style="grid-row: 5 / span 1">
<input type="password" name="password" id="password" placeholder="Enter password" style="grid-row: 6 / span 1">
<input type="checkbox" id="checkbox" onclick="seePassword()" style="grid-row: 6 / span 1">
<label for="checkbox" style="grid-row: 6 / span 1"></label>
<p id="password_prompt" style="grid-row: 7 / span 1">
Password must be at least 8 symbols length!
</p>
<input type="submit" id="submit_personal_data" value="Sign up" style="grid-row: 8 / span 1" disabled>
</div>
</div>
<div class="user_photo">
<div class="user_photo_grid">
<img src="{% static 'store/sign_up/default_avatar.png' %}" style="grid-row: 2 / span 5" id="avatar_image">
<input name="avatar" type="file" accept=".jpg, .jpeg, .png" id="submit_photo" onchange="displayIMG(this)">
<label for="submit_photo" style="grid-row: 8">Profile photo load</label>
</div>
</div>
</form>
So, what I want to ask about. When I don't include ImageField into my form and model - there is not any of errors, data adds into table correctly. But, when I include ImageField into my form and model like in example above - there is error - my form becomes invalid. I get information about my form in table, and this information is like this:
<tr><th><label for="id_surname">Surname:</label></th><td><input type="text" name="surname" value="Surname" maxlength="100" required id="id_surname"></td></tr>
<tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" value="Name" maxlength="100" required id="id_name"></td></tr>
<tr><th><label for="id_patronymic">Patronymic:</label></th><td><input type="text" name="patronymic" value="Patronymic" maxlength="100" required id="id_patronymic"></td></tr>
<tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" value="email#email.com" maxlength="100" required id="id_email"></td></tr>
<tr><th><label for="id_password">Password:</label></th><td><input type="text" name="password" value="password" maxlength="100" required id="id_password"></td></tr>
<tr><th><label for="id_avatar">Avatar:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="avatar" accept="image/*" required id="id_avatar"
Last string says, that the problem is there, in ImageField. I think that the problem may be in front, because when I add information about user (ImageFielf data also) in Django admin panel - operation is successfull.
So, why my form here is invalid?

You are forgetting enc-type.
your form should be like:
<form method="post" enctype="multipart/form-data">

On your model form avatar field you should type:
avatar = forms.ImageField(blank=True)
If that doesn't work, try this:
avatar = forms.ImageField(required=False)

try it like this:
<form method="post">
{% csrf_token %}
<div class="user_data">
<div class="user_data_grid">
<input type="text" name="surname" placeholder="Surname" id="surname" style="grid-row: 2 / span 1">
<input type="text" name="name" placeholder="Name" id="name" style="grid-row: 3 / span 1">
<input type="text" name="patronymic" placeholder="Patronymic" id="patronymic" style="grid-row: 4 / span 1">
<input type="email" name="email" placeholder="Enter your mail" id="email" style="grid-row: 5 / span 1">
<input type="password" name="password" id="password" placeholder="Enter password" style="grid-row: 6 / span 1">
<input type="checkbox" id="checkbox" onclick="seePassword()" style="grid-row: 6 / span 1">
<label for="checkbox" style="grid-row: 6 / span 1"></label>
<p id="password_prompt" style="grid-row: 7 / span 1">
Password must be at least 8 symbols length!
</p>
<div class="user_photo">
<div class="user_photo_grid">
<img src="{% static 'store/sign_up/default_avatar.png' %}" style="grid-row: 2 / span 5" id="avatar_image">
<input name="avatar" type="file" accept=".jpg, .jpeg, .png" id="submit_photo" onchange="displayIMG(this)">
<label for="submit_photo" style="grid-row: 8">Profile photo load</label>
</div>
</div>
<input type="submit" id="submit_personal_data" value="Sign up" style="grid-row: 8 / span 1" disabled>
</div>
</div>
</form>

Related

Django return none when y try to save in vars by POST method

I'm trying to save the data from a form by POST method. When i try to save in vars at views.py it put inside none
here i show important parts of my code:
add.html:
<form method="POST">
{% csrf_token %}
<h5>AÑADIR PEDIDO</h5>
<div class="form-group">
<label for="cliente">Nombre del Cliente</label>
<input type="text" class="form-control" id="cliente" placeholder="pepito" />
</div>
<div class="form-group">
<label for="producto">Codigo del Producto</label>
<select class="form-control" id="producto">
{% for cantidades in cantidad_pedido %}
<option value="{{cantidades.Cproducto}}">
{{cantidades.Cproducto}}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="cantidad">Cantidad de dicho producto</label>
<input type="number" class="form-control" id="cantidad" placeholder="cantidad" />
</div>
<button type="submit" class="btn btn-dark" style="margin-bottom: 1%;">Añadir!</button>
</form>
models.py:
class Stock(models.Model):
Cproducto = models.CharField(max_length=50, primary_key=True)
cantidad = models.IntegerField()
class Pedido(models.Model):
Cpedido = models.CharField(max_length=50, primary_key=True)
Ccliente = models.CharField(max_length=50)
FechaPedido = models.DateField(default=datetime.now)
class detallePedido(models.Model):
Cpedido = models.ForeignKey(Pedido, on_delete=models.CASCADE)
Cproducto = models.ForeignKey(Stock, on_delete=models.CASCADE)
Cantidad = models.IntegerField()
views.py :
def add(request):
cantidad_pedido = Stock.objects.all()
if request.POST:
client = request.POST.get('cliente')
producto = request.POST.get('producto')
cantidad = request.POST.get('cantidad')
stock_producto = Stock.objects.get(Cproducto=producto)
if(cantidad > stock_producto.cantidad):
messages.error(request, 'Error, la cantidad es mayor')
return render(request, 'add.html', {'cantidad_pedido': cantidad_pedido})
and here one picture of the vars:
You are missing as mention above in comment
I think you are making request with id attribute but instead of id you need to do with name attribute like this
form method="POST">
{% csrf_token %}
<h5>AÑADIR PEDIDO</h5>
<div class="form-group">
<label for="cliente">Nombre del Cliente</label>
<input type="text" class="form-control" name="cliente" placeholder="pepito" />
</div>
<div class="form-group">
<label for="producto">Codigo del Producto</label>
<select class="form-control" name="producto">
{% for cantidades in cantidad_pedido %}
<option value="{{cantidades.Cproducto}}">
{{cantidades.Cproducto}}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="cantidad">Cantidad de dicho producto</label>
<input type="number" class="form-control" name="cantidad" placeholder="cantidad" />
</div>
<button type="submit" class="btn btn-dark" style="margin-bottom: 1%;">Añadir!</button>
</form>
and you can use both id and name but for making request you need to name attribute

How to set the current date to an input type = date form in Django

I have been trying to make the date field in a form to display the current date when it renders. But I have failed to find a proper solution to this problem.
Please find below the code.
HTML File
<form class="form-horizontal" role="form" method = 'POST'>
{% csrf_token%}
<h2>New Manufacturer Details</h2>
<div class="form-group row">
<label for="createddate" class="col-sm-3 control-label">Created Date</label>
<div class="col-sm-9">
<input type="date" id="createddate" name = "createddate" class="form-control" autofocus required="true" value = '{{ createddate }}'>
</div>
</div>
<div class="form-group row">
<label for="manufname" class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
<input type="text" id="manufname" name = "manufname" placeholder="Manufacturer Name" class="form-control" autofocus required="true" value = '{{ manufname }}'>
</div>
</div>
<div class="form-group row">
<label for="manufaddress" class="col-sm-3 control-label">Address</label>
<div class="col-sm-9">
<textarea class="form-control" id="manufaddress" name = "manufaddress" placeholder="Manufacturer Address" rows="3" required="true" value = '{{ manufaddress }}'></textarea>
</div>
</div>
<div class="form-group row">
<label for="manufcontact" class="col-sm-3 control-label">Contact Name</label>
<div class="col-sm-9">
<input type="text" id="manufcontact" name = "manufcontact" placeholder="Manufacturer POC" class="form-control" autofocus required="true" value = '{{ manufcontact }}'>
</div>
</div>
<div class="form-group row">
<label for="manufcontactnum" class="col-sm-3 control-label">Contact Number</label>
<div class="col-sm-9">
<input type="text" id="manufcontactnum" name = "manufcontactnum" placeholder="Manufacturer Contact Number" class="form-control" autofocus required="true" value = '{{ manufcontactnum }}'>
</div>
</div>
<div class="form-group row">
<label for="manufemailid" class="col-sm-3 control-label">Email Id</label>
<div class="col-sm-9">
<input type="email" id="manufemailid" name = "manufemailid" placeholder="Manufacturer Email Id" class="form-control" autofocus required="true" value = '{{ manufemailid }}'>
</div>
</div>
<div class="form-group row">
<label for="manufgst" class="col-sm-3 control-label">GST No</label>
<div class="col-sm-9">
<input type="text" id="manufgst" name = "manufgst" placeholder="Manufacturer GST Number" class="form-control" autofocus required="true" value = '{{ manufgst }}'>
</div>
</div>
<div class="form-group row">
<label for="manuflicenseno" class="col-sm-3 control-label">License No</label>
<div class="col-sm-9">
<input type="text" id="manuflicenseno" name = "manuflicenseno" placeholder="Manufacturer License Number" class="form-control" autofocus required="true" value = '{{ manuflicenseno }}'>
</div>
</div>
<div class="form-group row">
<label for="manufbank" class="col-sm-3 control-label">Bank Details</label>
<div class="col-sm-9">
<textarea class="form-control" id="manufbank" name = "manufbank" placeholder="Manufacturer Bank Details" rows="3" required="true" value = '{{ manufbank }}'></textarea>
</div>
</div>
<div class="col text-center">
<button type="submit" class="btn btn-primary" id="form-submit">Save</button>
</div>
</form> <!-- /form -->
<script>
$("#form-horizontal").validate();
</script>
Views.Py
def createmanufacturer(request):
if request.method == 'POST':
form = CreateManufacturerForm(request.POST or None)
if form.is_valid():
form.save()
else:
createddate = request.POST['createddate']
manufname = request.POST['manufname']
manufaddress = request.POST['manufaddress']
manufcontact = request.POST['manufcontact']
manufcontactnum = request.POST['manufcontactnum']
manufemailid = request.POST['manufemailid']
manufgst = request.POST['manufgst']
manuflicenseno = request.POST['manuflicenseno']
manufbank = request.POST['manufbank']
messages.success(request, ('There was an error in your form! Please try again...'))
return render(request, 'screens/createmanufacturer.html', {
'createddate' : createddate,
'manufname' : manufname,
'manufaddress' : manufaddress,
'manufcontact' : manufcontact,
'manufcontactnum' : manufcontactnum,
'manufemailid' : manufemailid,
'manufgst' : manufgst,
'manuflicenseno' : manuflicenseno,
'manufbank' : manufbank,
})
messages.success(request, ('Manufacturer Details have been submitted successfully'))
return redirect("screens:testpage")
else:
form = CreateManufacturerForm()
return render(
request = request,
template_name = 'screens/createmanufacturer.html',
context = {'form' : form}
)
forms.py
class CreateManufacturerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CreateManufacturerForm, self).__init__(*args, **kwargs)
self.fields['createddate'].initial = date.today
class Meta:
model = Manufacturer
#createddate = forms.DateField(initial=date.today)
fields = ['createddate',
'manufname',
'manufaddress',
'manufcontact',
'manufcontactnum',
'manufemailid',
'manufgst',
'manuflicenseno',
'manufbank']
models.py
class Manufacturer(models.Model):
createddate = models.DateField()
manufname = models.CharField(max_length = 255)
manufaddress = models.TextField()
manufcontact = models.CharField(max_length = 255)
manufcontactnum = models.CharField(max_length = 25)
manufemailid = models.EmailField(max_length = 200)
manufgst = models.CharField(max_length = 255)
manuflicenseno = models.CharField(max_length = 255)
manufbank = models.TextField()
manufcode = models.CharField(max_length = 255, primary_key=True, editable=False)
def __str__(self):
return self.manufname
Right now, nothing happens when the form renders. What I want is the date in the Created Date should be set to today's date. However the user could leave it as is or could select a date of his/her choice. But the requirement is that date field should be pre-populated with the current date.
Please find below the screenshot of the web form.
Web Form
To save the current use auto_now=True
class DateField(auto_now=False, auto_now_add=False, **options)¶
A date, represented in Python by a datetime.date instance. Has a few extra, optional arguments:
DateField.auto_now¶
Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override
To display current date in the form use :
form = CreateManufacturerForm(initial={'createddate': datetime.now()})
So, after a lot of frustrating hours, I was able to finally solve the problem, with help from my friend Houda. This is what I did.
views.py
In the GET portion of the code, I wrote the following.
initial_data = {
'createddate' : date.today().strftime("%Y-%m-%d"),
}
form = CreateManufacturerForm(initial = initial_data)
template.html file
I changed the following
<input type="date" id="createddate" name = "createddate" class="form-control" autofocus required="true" value = '{{ form.createddate.value }}'>
I am not sure if this is the best solution. But at least I got it to work. I believe the issue had something to do with the date format that HTML has for the
input type = 'date'
it only allows 'YYYY-mm-dd'
Thanks everyone.

I can't submit the form even if it is valid

I have used CreateView for a form, but the form is not being submitted even when it is valid. It just redirects to the same page again.I am using the form_id for from fields, and it even submitted once or twice but now it is just not working.
models.py
class Centre(models.Model):
name= models.CharField(max_length=50, blank=False, unique=True)
address = models.CharField(max_length =250)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',
message="Phone number must be entered in the format: '+999999999'. Up to 10 digits allowed.")
contact = models.CharField(max_length=100, blank=False)
phone = models.CharField(validators=[phone_regex], max_length=10, blank=True)
views.py
class centre(CreateView):
fields = ('name','address','contact','phone',)
model = Centre
success_url = reverse_lazy("NewApp:logindex")
def form_valid(self, form):
form.save()
return super(centre, self).form_valid(form)
template :
<form method="POST">
{% csrf_token %}
<div class="col col-md-12">
<div class="fieldWrapper" >
{{ form.name.errors }}
<div class="form-group col col-md-3">
<label for="{{form.name.id_for_label}">Centre Name</label>
<input type="text" placeholder="Centre Name" name="name" maxlength="250" id="id_name" style="box-sizing: border-box; width:500px;">
</div>
</div>
<div class="form-group col col-md-3" style="float:right; margin-top=-80px;width=200%">
<label for="{{form.address.id_for_label}" style="margin-left:200px;width:200%;white-space:nowrap;">Centre Address</label>
<input type="text" placeholder="Centre Address" name="address" maxlength="250" id="id_address" style="width:500px; margin-left:200px;">
</div>
</div>
<br> <br><br><br>
<div class="col col-md-12">
<div class="form-group col col-md-3" style="float:right; margin-top=-80px;">
<label for="{{form.contact.id_for_label}" style="margin-left:200px;width:200px;white-space:nowrap;">Contact Person</label>
<input type="text" placeholder="Contact Person" name="address" maxlength="250" id="id_contact" style="width:500px; margin-left:200px;">
</div>
{{ user_form.non_field_errors }}
<div class="fieldWrapper" >
<div class="form-group col col-md-3" >
<label for="{{form.phone.id_for_label}" style="white-space:nowrap;">Contact Number</label>
<input type="text" name="phone" maxlength="10" id="id_phone" placeholder="Contact Number" style="width:500px";>
{{ form.phone.errors }}
</div>
</div>
</div>
<br>
<br>
<div class="col col-md-12" style="padding-left:4.5% ;padding-top:2%">
<input type="submit" value="Save" class="btn btn-primary" style=" height:30px;width:80px;padding-bottom:2em;"></input>
</div>
</form>
You have the wrong name attribute for the contact field, as a result of which it is not being submitted. At the same time, you are not outputting errors for that field.
(Note, you really should use the Django form tags to output the input elements; that would have avoided this situation, as well as pre-populating the fields when the template is redisplayed after validation.)

when i click the button to update my form CSRF verification failed pop ups

I have two different forms in my index.html template and in both the forms i'm using csrf token.
The problem that i'm facing is when I try to update my form i'm getting "CSRF verification failed. Request aborted." I've searched almost all the questions in this site and other websites and did everything still the error is shown.
This is my first form which adds student entry:
<form action = "{% url 'studentapp:addstudent' %}" id="addform" method = "POST">
{% csrf_token %}
<div class = "form-group">
<label for = "your_name">
Your name:
</label>
<input class = "form-control" id="new_name" type = "text" name="name" value="{{ current_name }}" placeholder="Enter your name">
</div>
<div class="form-group">
<label for = "course_name">
Course:
</label>
<input id="new_course" class = 'form-control' type = "text" name="course" value="{{ current_course }}" placeholder="Enter your course">
</div>
<div class = "form-group">
<label for = "rollno">
Roll No.:
</label>
<input id="new_rollno" type = "text" class = 'form-control' name="roll" value="{{ current_roll }}" placeholder="Enter your roll number">
</div>
<div class = "form-group">
<label for ="addr">
Address:
</label>
<textarea id="new_address" type = "text" name="address" class = 'form-control' value="{{ current_addr }}" placeholder="Enter your address"></textarea>
</div>
<input type = "submit" value="Submit" class = "btn btn-success" style="font-size:18px;" />
</form>
This is my second form which is pre-populated when i click "edit" button on my template. when i click "update" button csrf token verification failed is displayed.
<form action="{% url 'studentapp:editrow' rowid=id %}" id="editform" method="POST">
{% csrf_token %}
<div class = "form-group">
<label for = "your_name">
Your name:
</label>
<input class = "form-control" id="new_name" type = "text" name="name" value="{{ student_detail.name }}" placeholder="Enter your name">
</div>
<div class="form-group">
<label for = "course_name">
Course:
</label>
<input id="new_course" class = 'form-control' type = "text" name="course" value="{{ student_detail.course }}" placeholder="Enter your course">
</div>
<div class = "form-group">
<label for = "rollno">
Roll No.:
</label>
<input id="new_rollno" type = "text" class = 'form-control' name="roll" value="{{ student_detail.roll }}" placeholder="Enter your roll number">
</div>
<div class = "form-group">
<label for ="addr">
Address:
</label>
<input id="new_address" type = "text" name="address" class = 'form-control' value="{{ student_detail.address }}" placeholder="Enter your address"/>
</div>
<input type = "submit" value="Update" id="update" class = "btn btn-success" style="font-size:18px;" />
</form>
</div>
</div>
</div>
</div>
This is my ajax request:
function update_entry(id) {
var id = id
$.ajax({
url: "{% url 'studentapp:index' %}",
type: "POST",
data:{
'csrfmiddlewaretoken': '{{ csrf_token }}',
'id' : id,
},
success: function(response){
$(".response").html(response.template)
$("#editform").modal("show");
}
});
}
function update_property(id) {
window.location.replace("/studentapp/editrow" + id+"/");
}
Since I was using two separate forms, i was using two CSRF tokens. Removing one token was not solving the issue so I just did this:
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
in one of my forms and added these two lines in my index view:
if request.is_ajax():
#Your Code
csrf_token = request.POST['csrfmiddlewaretoken']
response = {}
response['status'] = False
student_detail = #Your Model name
context = {
"Your dictionary"
"csrf_token": csrf_token
}
and it's working just fine for me.

Django User Form don't save on database

I've create a Model, Form, View and register.html but my form doesn't save on database and doesn't create a new user. What's wrong?
Follow the codes...
models.py
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
class Cliente(models.Model):
SEXO_CHOICES = (
(u'Masculino', u'Masculino'),
(u'Feminino', u'Feminino'),
)
nome = models.CharField(max_length=50, null=False, default='*')
telefone = models.CharField(max_length=20, null=True)
cpf = models.CharField(max_length=255, null=False)
data_de_nascimento = models.DateField(null=False)
sexo = models.CharField(max_length=9, null=False, choices=SEXO_CHOICES)
usuario = models.OneToOneField(User, related_name="cliente")
#property
def email(self):
return self.usuario.email
def __unicode__(self):
return self.nome
forms.py
from django import forms
from django.contrib.auth.models import User
from datetimewidget.widgets import DateTimeWidget, DateWidget, TimeWidget
from clientes.models import Cliente
class RegistraClienteForm(forms.Form):
SEXO_CHOICES = (
(u'Masculino', u'Masculino'),
(u'Feminino', u'Feminino'),
)
nome = forms.CharField(required=True)
telefone = forms.CharField(required=True)
cpf = forms.CharField(required=True)
data_de_nascimento = forms.DateField(
widget=DateWidget(usel10n=True, bootstrap_version=3)
)
sexo = forms.ChoiceField(required=True, choices=SEXO_CHOICES)
username = forms.CharField(required=True)
email = forms.EmailField(required=True)
senha = forms.CharField(required=True)
def is_valid(self):
valid = True
if not super(RegistraClienteForm, self).is_valid():
self.adiciona_erro('Por favor, verifique os dados informados')
valid = False
return valid
username_form_data = self.data['username']
user_exists = User.objects.filter(username=username_form_data).exists()
if user_exists:
self.adiciona_erro('User already exists!')
valid = False
return valid
def adiciona_erro(self, message):
errors = self._errors.setdefault(
forms.forms.NON_FIELD_ERRORS,
forms.utils.ErrorList()
)
errors.append(message)
And the register.html
{% extends "new_client_base.html" %}
{% block body %}
<form class="form-signin" action="{% url 'registrar' %}" method="post">
{% csrf_token %}
<h2 class="form-signin-heading">Crie seu usuário</h2>
<label for="id_nome"> Nome: </label> <input name="nome" type="text" id="id_nome" class="form-control" placeholder="Nome *" required autofocus/>
<label for="id_telefone">Telefone: </label> <input type="text" name="telefone" id="id_telefone" class="form-control" placeholder="Telefone *" required/>
<label for="id_cpf"> CPF: </label> <input type="text" name="cpf" id="id_cpf" class="form-control" placeholder="CPF *" required/>
<label for="id_data"> Data de Nascimento:</label> <input type="date" name="data_de_nascimento" id="id_data" class="form-control" required />
<label for="id_sexo" class="required">
Sexo:
</label> <select id="id_sexo" name="sexo">
<option selected="selected" value=""> ------- </option>
<option value="Masculino"> Masculino </option>
<option value="Feminino"> Feminino </option>
</select>
<label for="id_username"> Nome de usuário: </label> <input type="text" name="username" class="form-control" id="id_username" required/>
<label for="id_email"> Email: </label> <input type="text" name="email" id="id_email" class="form-control" required />
<label for="id_pass"> Senha: </label> <input type="password" name="senha" id="id_pass" class="form-control" required>
<button
type="submit"
class="btn btn-lg btn-primary btn-block"
value="login"
>
Registrar
</button>
{% if form.errors %}
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true" name="button">×</button>
{{form.non_field_errors}}
</div>
{% endif %}
</form>
{% endblock %}
I want to know how to save this data, why save() method does not work and how can I format date in DD-MM-YYYY and show a minicalendar.
Thanks.

Categories

Resources