I already made a review form where user can give their feedback on the service. The form works perfectly, and data is also stored in the database. There is a rating star options as well. Now I just want to make a system where the user just can do one review. If a user did a review the review form won't show to the user. Now, what should I do? and What'll be the logic?
models.py:
class Frontend_Rating(models.Model):
USer = models.ForeignKey(User,default=None,on_delete=models.CASCADE, related_name="frontend_rating")
Rating = models.IntegerField(null=True)
Feedback = models.TextField(max_length=250, null=True)
template:
<form action="frontend_ratings/" class="mt-3" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="radio-toolbar d-flex justify-content-center ">
<input type="radio" id="one_star" name="frontend_ratting" value="1" checked>
<label for="one_star" class="mx-1">1 <i class="fas fa-star"></i></label>
<input type="radio" id="two_star" name="frontend_ratting" value="2">
<label for="two_star" class="mx-1">2 <i class="fas fa-star"></i></label>
<input type="radio" id="three_star" name="frontend_ratting" value="3">
<label for="three_star" class="mx-1">3 <i class="fas fa-star"></i></label>
<input type="radio" id="four_star" name="frontend_ratting" value="4">
<label for="four_star" class="mx-1">4 <i class="fas fa-star"></i></label>
<input type="radio" id="five_star" name="frontend_ratting" value="5">
<label for="five_star" class="mx-1">5 <i class="fas fa-star"></i></label>
</div>
<!-- feedback area-->
<div class="d-flex justify-content-center">
<textarea style="font-size: small;" maxlength="250" name="frontend_feedback"
placeholder="Share your experience in 250 charecters...."
class="col-10 mt-2 hireme_textarea btn montserrat text-left d-block" required
rows="5"></textarea>
</div>
<div class="d-flex justify-content-center mt-3">
<button type="submit" class="btn singUpBtn col-10 submit_btn_sing_up_in sing_up_js1"
id="message">Save</button>
</div>
</form>
Related
Good day people, a part of my project has a form action that takes user input and saves it in the database. the user has an option to either select the category from the select field or enter a new category if the category does not exit in the select field but I get "MultiValueDictKeyError at upload/"
below is the template and the corresponding view to the form action:
upload.html
{%extends 'base.html'%}
{%block content%}
<div class="container" id="containers">
<div class="row" style="width: 40%;">
<form action="upload" method="post" enctype="multipart/form-data">
{% csrf_token %}
<ul class="collection">
<li class="collection-item">
<div class="input-field" >
<input placeholder="Enter the product name here..." id="first_name" type="text" class="validate" name="product_name">
<label for="first_name">Product name</label>
</div>
</li>
<li class="collection-item">
<div class="input-field" >
<select class="browser-default" name="the_category">
<option value="" disabled selected>Category</option>
{% for category in categories %}
<option value="{{category.name}}">{{category.name}}</option>
{% endfor%}
</select>
</div>
</li>
<li class="collection-item">
<div class="input-field" style="margin: 5px;">
<input name="new_category" placeholder="Type here..." id="first_name" type="text" class="validate">
<label for="first_name">New Category</label>
</div>
</li>
<li class="collection-item"><div class="input-field " >
<input placeholder="Enter the price"id="username" type="number" class="validate" name="prize">
<label for="password">Price</label>
</div>
</li>
<li class="collection-item">
<div class="input-field">
<input name="locate" placeholder="Enter the location" id="first_name" type="text" class="validate">
<label for="first_name">Location</label>
</div>
</li>
<li class="collection-item">
<div class="input-field" >
<textarea id="textarea1" class="materialize-textarea" name="describe"></textarea>
<label for="textarea1">Descriptiion</label>
</div>
</li>
<li class="collection-item">
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type="file" name="image">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</ul>
<button class="btn waves-effect waves-light right" type="submit" name="action">Submit
<i class="material-icons right">send</i>
</button>
</form>
</div>
</div>
{%endblock content%}
views.py (for upload)
def upload(request):
categories=Category.objects.all()
if request.method=='POST':
images=request.FILES.get('image')
data=request.POST
location,created=LOCATION.objects.get_or_create(Location=data['locate'])
if data['the_category']!='none':
category=Category.objects.get(name=data['the_category'])
elif data['new_category']!='':
category=Category.objects.create(name=data['new_category'])
else:
category=None
models.Product.objects.create(
name=data['product_name'],
image=images,
category=category,
description=data.get('describe'),
Location=location,
price=data.get('prizes'),
created=datetime.datetime.now(),
is_available=True
)
return render(request,'upload.html',{'categories':categories})
i am trying to create edit profile form, in which i am trying to data from edit profile form. i am getting all data in request.POST but i am getting empty {} using request.Files
view.py
class EditProfile(View):
template_name="todo_app/edit_profile.html"
def get(self,request,pk):
if request.user.is_authenticated:
user_id=pk
profile=UserProfile.objects.get(user=user_id)
content={
'profile':profile,
}
return render(request,self.template_name,content)
else:
return redirect('todo_app:login')
def post(self,request,pk):
request_data=request.POST
first_name=request_data.get('first_name')
last_name=request_data.get('last_name')
mob_no=request_data.get('mob_no')
address_1=request_data.get('address_1')
address_2=request_data.get('address_2')
gender=request_data.get('gender')
age=request_data.get('age')
state=request_data.get('state')
city=request_data.get('city')
country=request_data.get('country')
bio=request_data.get('bio')
# profile_pic=request.FILES['profile_pic']
print(request_data)
print("_"*123)
print(request.FILES)
return redirect('todo_app:edit_profile',pk)
and print result on console is
<QueryDict: {'csrfmiddlewaretoken': ['mkfuwR6Uc99svosQvsVpho11JOXOdESSmp2sm1ULDFrFu3UHRrkASTWeSyRwXyzH'], 'first_name': ['upasana'], 'last_name': ['kulshresths'], 'address_1': ['9 Purushottam Nagar'], 'address_2': ['Dayal Bagh'], 'mob_no': ['9087654321'], 'gender': ['Male'], 'age': ['12'], 'state': ['Uttar Pradesh'], 'city': ['Agra'], 'country': ['India'], 'bio': ['Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professo'], 'profile_pic': ['Screenshot from 2021-07-14 16-44-31.png']}>
___________________________________________________________________________________________________________________________
<MultiValueDict: {}>
edit_profile.html
<form method="POST" action="{% url 'todo_app:edit_profile' profile.user.id %}" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="first_name">First name</label>
<input type="text" class="form-control" id="first_name" value="{{profile.user.first_name}}" name="first_name" required>
</div>
<div class="col-md-6 mb-3">
<label for="last_name">Last name</label>
<input type="text" class="form-control" id="last_name" value="{{profile.user.last_name}}" name="last_name" required>
</div>
<div class="col-md-6 mb-3">
<label for="address_1">Address line 1</label>
<input type="text" class="form-control" id="address_1" value="{{profile.address_line_1}}" name="address_1" required>
</div>
<div class="col-md-6 mb-3">
<label for="address_2">Address line 2</label>
<input type="text" class="form-control" id="address_2" value="{{profile.address_line_2}}" name="address_2" required>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="mobile_no">Mobile No</label>
<input type="number" min="6000000000" max="9999999999" value="{{profile.user.mob_no}}" class="form-control" id="mobile_no" name="mob_no" required>
</div>
<div class="col-md-3 mb-3">
<label for="gender">Gender</label>
<select class="custom-select" id="gender" name="gender" required>
<option>Male</option>
<option>Female</option>
<option>๐ณ๏ธโ๐</option>
</select>
</div>
<div class="col-md-3 mb-3">
<label for="age">Age</label>
<input type="number" min="0" max="120" value="{{profile.age}}" class="form-control" id="age" name="age" required>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="State" class="form-label">State</label>
<input type="text" class="form-control" id="State" name="state" value="{{profile.state}}">
</div>
<div class="col-md-3 mb-3">
<label for="city" class="form-label">City</label>
<input type="text" class="form-control" id="city" name="city" value="{{profile.city}}">
</div>
<div class="col-md-3 mb-3">
<label for="country" class="form-label">Country</label>
<input type="text" class="form-control" id="country" name="country" value="{{profile.country}}" >
</div>
</div>
<div class="form-row">
<div class="col-md-10 mb-3">
<label for="bio">Bio</label>
<textarea class="form-control" placeholder="Leave a comment here" id="bio" style="height: 100px" name="bio">{{profile.bio}}</textarea>
</div>
<div class="col-md-2 mb-3 ml-auto mt-4">
<img src="{{profile.profile_pic.url}}" class="rounded-circle" width="100px" alt="...">
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="profile_pc_spam">Profile Pic</span>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" id="profile_pic" name='profile_pic' >
<label class="custom-file-label" for="profile_pic">Choose file</label>
</div>
</div>
<div class="text-center">
<button class="btn my_button_delete mb-4 ustify-content-center" type="submit" >Submit form</button>
</div>
</form>
what am I doing wrong? i don't want to use django forms.
i try to search old question related this problem on stack overflow but i found that every one suggest using django form. if i missed any answer please tag me
Model.py file
from django.db import models
from django.contrib.auth.models import User
class ClientDetails(models.Model):
objects = models.Manager()
username = models.CharField(max_length=20, unique=True)
gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
Mobile_no = models.IntegerField(blank=True)
address = models.TextField(blank=True)
online = models.BooleanField(default=True)
def __str__(self):
return self.username
class Meta:
verbose_name = 'ClientDetail'
verbose_name_plural = 'ClientDetails'
forms.py file using this form i am storing the users data user
from django.forms import models
from django import forms
from Client.models import ClientDetails
class ClientDetailsForm(models.ModelForm):
class Meta:
model = ClientDetails
fields = ['Assignment','email','username','gender', 'Mobile_no', 'address','city','Joining_branch',
'Work_type','candidate_job_level', 'submission_date', 'submission_time',
'candidate_photo', 'created_by', 'amount_paid', 'name','fix_or_custom']
AdminPanel/create_account.html this file is from AdminPanel/templates which creates the user and also store the data into ClientDeatils
<form action="{% url 'AdminPanel:fixed_target_account'%}" method="POST"
enctype="multipart/form-data">
{% csrf_token %}
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-at text-black-50"></i>
<input type="text" class="form-control text-dark" name="username" style="border:1px solid gray" placeholder="Username">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-user"></i>
<input type="text" class="form-control text-dark" name="name" style="border:1px solid gray" placeholder="Full Name">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-genderless"></i>
<select class="form-control text-dark" name="gender" style="border:1px solid gray" required="" id="id_gender">
<option value="" selected="">---------</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-mobile-alt"></i>
<input type="text" class="form-control text-dark" name="Mobile_no" style="border:1px solid gray" placeholder="Mobile No.">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-map-marker-alt"></i>
<input type="text" class="form-control text-dark" name="address" style="border:1px solid gray" placeholder="Address">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon far fa-map"></i>
<input type="text" class="form-control text-dark" name="city" style="border:1px solid gray" placeholder="City">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-code-branch"></i>
<select class="form-control text-dark" name="Joining_branch" style="border:1px solid gray" required="" id="id_Joining_branch">
<option value="" selected="">---------</option>
<option value="Bhandup West">Bhandup West</option>
</select>
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-info-circle"></i>
<select class="form-control text-dark" name="Work_type" style="border:1px solid gray" required="" id="id_Work_type">
<option value="" selected="">---------</option>
<option value="CopyPaste">Copy Paste</option>
<option value="ODT">ODT</option>
</select>
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-check-square"></i>
<input type="text" class="form-control text-dark" name="candidate_job_level" style="border:1px solid gray" placeholder="Candidate job level">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-form"></i>
<select style="border:1px solid gray" class="form-control text-dark" name="Assignment" required="" id="id_Assignment">
<option value="" selected="">---------</option>
<option value="Assignment 1">Assignment 1</option>
<option value="Assignment 2">Assignment 2</option>
<option value="Assignment 3">Assignment 3</option>
<option value="Assignment 4">Assignment 4</option>
<option value="Assignment 5">Assignment 5</option>
<option value="Assignment 6">Assignment 6</option>
</select>
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon far fa-calendar-alt"></i>
<input type="text" class="form-control text-dark" name="submission_date" style="border:1px solid gray" placeholder="Submission Date">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon far fa-calendar-times"></i>
<input type="text" class="form-control text-dark" name="submission_time" style="border:1px solid gray" placeholder="Submission time">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-mail"></i>
<input type="text" class="form-control text-dark" name="email" style="border:1px solid gray" placeholder="Email ID">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-smile"></i>
<input type="file" class="form-control text-dark" name="candidate_photo" style="border:1px solid gray" accept="image/*" required="" id="id_candidate_photo">
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-user"></i>
<select class="form-control text-dark" name="created_by" style="border:1px solid gray" required="" id="id_created_by">
<option value="" selected="">---------</option>
<option value="1">faijan</option>
</select>
</div>
</div>
<div class='container' style="width:60%;">
<div class="input-affix m-b-10">
<i class="prefix-icon fas fa-rupee-sign"></i>
<input type="text" class="form-control text-dark" name="amount_paid" style="border:1px solid gray" placeholder="Amount Paid">
</div>
</div>
<select hidden name="fix_or_custom" required="" id="id_fix_or_custom">
<option value="Fix" selected >Fix</option>
</select>
<div class="text-center" style="content:50%;">
<button class='btn btn-success btn-lg '>Create</button>
</div>
</form>
AdminPanel/views.py in this file I successfully created the user and stored the user data
def fixed_target_account(request):
if request.method == "POST":
form = ClientDetailsForm(request.POST, request.FILES)
try:
user = User.objects.create_user(request.POST['username'], password=request.POST['Mobile_no'])
user.save()
except IntegrityError:
return render(request, 'AdminPanel/fixed_target_account.html', {'form':ClientDetailsForm,'error':"Username is already been taken."})
if form.is_valid:
newform = form.save(commit=False)
newform.user = request.user
newform.save()
return redirect('AdminPanel:dashboard')
else:
return render(request, 'AdminPanel/fixed_target_account.html', {'form':ClientDetailsForm,'error':"Please enter the valid data."})
else:
pass
return render(request, 'AdminPanel/fixed_target_account.html')
Client/Views.py file here I want when user logs in his online status should be set to true [even though it is]
def loginuser(request):
''' code for logging in the user also when logged in update staus to active '''
if request.method == "POST":
user = authenticate(username=request.POST['username'], password=request.POST['password'])
login(request, user)
# get the id of the user
pk = request.user.id
ClientDetails.objects.filter(id=pk).update(online=True)
return redirect('Client:dashboard')
else:
return render(request, 'Client/loginuser.html')
when he sign's out his online status should be set to False I tried other ways and this as well but its not updating the status in backend [at admin side ]
def sign_out(request):
''' before logging out the user update his online status to False '''
pk = request.user.id
print(pk)
ClientDetails.objects.filter(id=pk).update(online=False)
logout(request)
return render(request, 'Client/loginuser.html')
loginuser.html file
<div class="card-body">
<div class="d-flex align-items-center justify-content-between m-b-30">
<img class="img-fluid" alt="" src="{% static 'assets/images/logo/logo.png' %}">
<h2 class="m-b-0">Sign In</h2>
</div>
<form action="{% url 'Client:login' %}" method="POST">
{% csrf_token %}
<div class="form-group">
<label class="font-weight-semibold" for="userName">Username:</label>
<div class="input-affix">
<i class="prefix-icon anticon anticon-user"></i>
<input type="text" class="form-control" name="username" id="userName" placeholder="Username">
</div>
</div>
<div class="form-group">
<label class="font-weight-semibold" for="password">Password:</label>
<a class="float-right font-size-13 text-muted" href="">Forget Password?</a>
<div class="input-affix m-b-10">
<i class="prefix-icon anticon anticon-lock"></i>
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="d-flex align-items-center justify-content-between">
<span class="font-size-13 text-muted">
Don't have an account?
<a class="small" href=""> Signup</a>
</span>
<button type="submit" class="btn btn-primary">Sign In</button>
</div>
</div>
</form>
</div>
Your ClientDetails model isn't actually linked in any way to the model that's used for your user authentication. This model is probably called something like User, although we can't be certain of that with the given information in the question.
When you fetch the id of the currently authenticated user from the request with request.user.id, this is actually referencing a User instance and not a ClientDetails instance. So the line ClientDetails.objects.filter(id=pk) will most likely either give you the wrong ClientDetails instance or none at all and thus update(online=True) will normally not updated the instance you expect it to update.
So you either have to link your ClientDetails with a foreign key to your User object and then use that link to query, or you can presumably use the username from the User instance and use that in your query on ClientDetails like so: ClientDetails.objects.filter(username=request.user.get_username()).
Im new to django i want create signup form with my own feild ,i dont want to signup form in default that is in user table i want to created own custom sign up forn any can hepl plz
Im new to django i want create signup form with my own feild ,i dont want to signup form in default that is in user table i want to created own custom sign up forn any can hepl plz
here is my example how my form feild look like
[enter link description here][1]
<form id="contact-form" method="post" action="/addyourschool/" role="form">
<input type="hidden" name="csrfmiddlewaretoken" value="vhcAZ5w1HpK2mUXMhdqHR1to9Yv2LeOB85E2kR7Z1ZsPo5fjtWZ5P7o23kj8lDsk">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">School Name</label>
<input type="text" name="schoolname" id="product" class="form-control ui-autocomplete-input" placeholder="Type few letter & select from down *" required="required" data-error="Lastname is required." autocomplete="off">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_cfschp">Can't find your School *</label>
<input id="form_cfschp" type="text" name="form_cfschpool" class="form-control" placeholder="Can't find your School *" required="required" data-error="Can't find your School">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="Pessonname">Contact person Name *</label>
<input id="Pessonname" type="text" name="Pessonname" class="form-control" placeholder="Contact person Name *" required="required" data-error="Contact person Name ">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="DesignationatSchool">Designation at School(job title at this section) *</label>
<select id="DesignationatSchool" name="DesignationatSchool" class="form-control" required="required" data-error="Designation at School">
<option value=""></option>
<option value="Request principal">Principal</option>
<option value="Request quotation">Founder</option>
<option value="Request order status">Management</option>
<option value="Request copy of an invoice">Teachers</option>
<option value="Other">Others</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="pwd">Password *</label>
<input id="pwd" type="password" name="password" class="form-control" placeholder="Enter your Password *" required="required" data-error="password">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="pwd">Confirm Password *</label>
<input id="pwd" type="password" name="password" class="form-control" placeholder="Confirm Password *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="email">Email *</label>
<input id="email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="tel">Mobile No. *</label>
<input id="tel" type="tel" name="phone" class="form-control" placeholder="Please enter your Mobile No *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="text-center"> <input type="submit" class="btn btn-success btn-send" value="Register"></div>
<div class="text-center">Aready Register / have an account ? Login here</div>
</div>
</div>
</form>
from django import forms
class RegisterForm(forms.Form):
username = forms.CharField(max_length=50)
email = forms.EmailField(max_length=50)
subject = forms.CharField(max_length=50)
message = forms.CharField(widget=forms.Textarea)
You have to first create the forms.py file in your app as e.g(contact_us)
from django.shortcuts import render
from django.core.mail import send_mail
from .forms import RegisterForm
from django.http import HttpResponse
Create your views here.
def contact_us(request):
#request for POST
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
sender_name = form.cleaned_data['username']
sender_email = form.cleaned_data['email']
message = "{0} has sent you a new message:\n\n{1}".format(sender_name, form.cleaned_data['message'])
send_mail('New Enquiry', message, sender_email, ['example#gmail.com'])
return HttpResponse('Thanks for Contacting US')
else:
form = RegisterForm()
return render(request, 'Contactus/contact.html', {'form': form})
After created the forms you have to insert the forms class name in views.py to display the custom form on browser.
#Create Your Template
<form id="contactform" method="POST">
{% csrf_token %}
<div class="column one-second">
{{ form.username }}
</div>
<div class="column one-second">
{{form.email }}
</div>
<div class="column one">
{{ form.subject }}
</div>
<div class="column one">
{{ form.message }}
</div>
<div class="column one">
<input type="submit" value="submit">
</div>
</form>
After this you have to call the form in template. To display your own custom form.
As i did above.
I am using Django and Bootstrap on frontend to write a single profile editing module.
Plain form from Django is ugly, so I did some custimizing on the form. Here is the HTML form:
<form actoin="{% url 'edit_profile' %}" method="post">
{% csrf_token %}
<div class="form-group row">
<label for="chineseName" class="col-sm-2 control-label">name</label>
<div class="col-sm-10">
<input name="chinese_name" class="form-control" id="chineseName" placeholder="name" value="{{form.chinese_name.value}}">
</div>
</div>
<div class="form-group row">
<label for="gender" class="col-sm-2 control-label">gender</label>
<div class="col-sm-10">
<label class="radio-inline">
{% if form.gender.value == "M" %}
<input type="radio" name="gender" id="gender1" value="M" checked> Male
{% else %}
<input type="radio" name="gender" id="gender2" value="M"> Male
{% endif %}
</label>
<label class="radio-inline">
{% if form.gender.value == "F" %}
<input type="radio" name="gender" id="gender1" value="F" checked> Female
{% else %}
<input type="radio" name="gender" id="gender2" value="F"> Female
{% endif %}
</label>
</div>
</div>
<div class="form-group row">
<label for="age" class="col-sm-2 control-label">age</label>
<div class="col-sm-10">
<input name="age" class="form-control" id="age" placeholder="ๅนด้พ" value="{{form.age.value}}">
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-sm-2 control-label">phone</label>
<div class="col-sm-10">
<input name="phone" class="form-control" id="phone" placeholder="phone" value="{{form.phone.value}}">
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default col-xs-12" id="confirm" style="display:none;">confirm</button>
</div>
</div>
</form>
Somehow request.POST is not receiving data from this form. When I switch this long HTML snippet into {{form}}, everything is fine.
So view function is correct. Is there anything wrong with this template file, especially the form part?
You should add the css in the form class, for example if you are using ModelForm:
self.fields['phone'].widget.attrs['placeholder'] = self.fields['phone'].label
or if you are using Form :
phone = forms.CharField(widget=forms.TextInput(attrs={'placeholder' : 'phone'))
Nothing looks out of order at first look. One way to debug further would be to instantiate the form and print it. Then compare everything, especially the <form> tag and <input> tags.