Django form is saved but result field is empty in database - django

Django form is saved but "result" field is showing empty in database.
Even after populating the filed from admin panel, it is saved but it still shows empty.
Models.py
class Result(models.Model):
class Choises(models.TextChoices):
POSITIVE = "POSITIVE", "Positive"
NEGATIVE = "NEGATIVE", "Negative"
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=50, default=None)
result = models.CharField(max_length = 100, choices=Choises.choices, blank=False
)
resultDoc = models.ImageField(upload_to='testResults', height_field=None, width_field=None,)
def __str__(self):
return self.user.username
Forms.py
class resultForm(forms.ModelForm):
class Meta:
model = Result
fields = ['name', 'result', 'resultDoc']
views.py
def inputResult(request, pk):
user = User.objects.filter(id=pk).first()
profile = newProfile.objects.filter(user=user).first()
if profile == None:
profile = oldProfile.objects.filter(user=user).first()
rForm = resultForm(request.POST, request.FILES)
if request.method == 'POST':
rForm = resultForm(request.POST, request.FILES)
if rForm.is_valid():
order = rForm.save(commit=False)
order.user_id = pk
order.save()
return redirect('stored_records')
else:
rForm = resultForm()
context = {'user' : user, 'profile':profile, 'rForm': rForm}
return render(request, 'Testing booth End/input-result-customer-info.html', context)
input-result-customer-info.html
<form action="" method = "POST" enctype= "multipart/form-data">
{% csrf_token %}
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Uploaded By/Doctor Name">
</div>
<div class="mb-3">
<label for="result" class="form-label">Result</label>
<select class="form-select" id="result" name="result" class="form-control">
<option value="POSITIVE">Positive</option>
<option value="NEGATIVE">Negative</option>
</select>
</div>
<div class="mb-3">
<label>Upload Scan File</label>
<div class="upload d-flex justify-content-between">
<div class="file-placeholder">Upload Scan File</div>
<input type="file" class="form-control d-none" id="resultDoc" name="resultDoc" >
<label for="resultDoc" class="form-label cam-img"> <img src="{% static 'user/images/Camera.png' %}"> </label>
</div>
</div>
<button class="btn btn-primary w-50 ms-auto d-block h-100" type="submit">Upload</button>
</form>
enter image description here

I think that the reason this doesnt work is that you created a form (rForm) in the backend but then you don't use it in the frontend.
This is how you should render your form in the the frontend:
<form method="post">
{{ rForm.as_p }} # This is the easiest possible implementation
<button type="submit">Submit</button>
</form>
If you want to take control of how the form is rendered, then you have to make sure that the input fields are named in the way that your backend expects. You can do it entirely manually or semi-manually, but your field names have to be set correctly or nothing will work.
Example of typical approach, say in case you have several similar text inputs
{% for field in rForm %}
<label for="{{ field.auto_id }}">{{ field.name }}</label>
<input type="text" name="{{ field.html_name }}" id="{{ field.auto_id }}" />
{% endfor %}
Example of fully hands-on approach
<select class="form-select" id="{{ rForm.result.auto_id }}" name="{{ rForm.result.html_name }}" class="form-control">
<option value="POSITIVE">Positive</option>
<option value="NEGATIVE">Negative</option>
</select>
In order to make sure that the inputs are being parsed correctly, add a print statement in your view to print the POST request:
print("Post Request : ", request.POST)
From there you will be able to see if the result field is being picked up correctly or if it's being ignored. Usually when fields get ignored is because they are not named correctly or sometimes it's because they fail validation.
If the rest of the data is saved correctly and just result is being left out then it's almost for sure an issue with the field name because if the form failed validation it would have aborted the entire operation.
P.S. I just noticed that you select input has the class attribute declared twice

Related

Processing a Django form

I have a problem using Django forms while learning Django and adapting code from a variety of online courses and examples. As a result, the code may be “messy” – but if I can get it to work the way I need, I can improve my coding style later.
I wish to display a template that contains a form. Some of the data displayed in the page rendered in the template is read from one table/model, polls_CC_Questions, and I wish to write data input in the page into a related table, polls_CC_Resp_NoFK.
The models used are:
class CC_Questions(models.Model):
q_text = models.CharField('Question text', max_length=200)
C1_Type = models.CharField('Choice 1 Type', max_length=2)
Choice1_text = models.CharField('Choice 1 text', max_length=100)
C2_Type = models.CharField('Choice 2 Type', max_length=2)
Choice2_text = models.CharField('Choice 2 text', max_length=100)
#
def __str__(self):
return self.q_text[:20]
class CC_Resp_NoFK(models.Model):
Person_ID = models.IntegerField()
Test_date = models.DateTimeField('date test taken')
Q_ID = models.IntegerField()
Response_value = models.IntegerField(default=0,
validators=[MaxValueValidator(100), MinValueValidator(-100)])
#
def __str__(self):
return self.Person_ID
Now I can display the template containing valid data when I enter the url:
http://localhost:8000/polls/p2vote/4/
This is processed in urls.py
app_name = 'polls'
urlpatterns = [
…..
……
# ex: /polls/p2vote/<q_id>
path('p2vote/<int:q_id>/', p2_views.p2vote, name='p2vote'),
…..
The views.py entry that is used:
def p2vote(request,q_id):
#next line has been copied from CC_quest view to GET Question data
CC_question = get_object_or_404(CC_Questions, pk=q_id)
#
if request.method == 'POST':
form = VoteForm(request.POST)
if form.is_valid():
form.save()
return redirect('/polls/p2')
else:
formV = VoteForm()
#context = {'form' : formV}
return render(request, 'pollapp2/vote.html', {'var_name':CC_question,'form' : VoteForm()})
in forms.py
class VoteForm(forms.ModelForm):
class Meta:
model = CC_Resp_NoFK
fields = ['Person_ID', 'Test_date', 'Q_ID','Response_value']
The template launched, uses data from the polls_CC_Questions model/table to create the labels of the input field. This works fine so my displayed page
http://localhost:8000/polls/p2vote/5/
Displays data from the CC_Questions table, “carried in the variable varname” what the questions and their choices are. For example, the template displays the contents of {{ var_name.q_text }} and {{ var_name.Choice1_text }} , see below
Also, the page displayed containing the ModelForm is correctly displayed with labels. The template used :
<!-- vote.html based on create.html -->
<!-- 2022-02-17
Change text on page
Extracted data from CC_Question record passed as varname
-->
{% extends "pollapp2/base.html" %}
<!-- load widget tools to give me more control over layout of form in template -->
{% load widget_tweaks %}
<!-- block Title is the name in the tab -->
{% block title %}Vote on Question{% endblock %}
{% block main %}
<div class="row">
<div class="col-lg-10 col-lg-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Select one from two choices</h3>
</div>
<form method="POST">
{% csrf_token %}
<div class="panel-body">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label for="question">Question to answer</label>
{{ var_name.q_text }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-5">
<div class="form-group">
<label for="Choice1_text ">Choice 1</label>
{{ var_name.Choice1_text }}
</div>
</div>
<div class="col-lg-5">
<div class="form-group">
<label for="option2">Choice 2</label>
{{ var_name.Choice2_text }}
</div>
</div>
</div>
<!-- Attempt at Input fields follow -->
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label for="Person_id">Person ID</label>
{% render_field form.Person_ID rows="1" class="form-control" %}<br>
<label for="Test_date">Test Date</label>
{% render_field form.Test_date rows="1" class="form-control" %}<br>
<label for="Q_ID">Question ID</label>
{% render_field form.Q_ID rows="1" class="form-control" %} <br>
<label for="Response_value">Response value</label>
{% render_field form.Response_value rows="1" class="form-control" %}
</div>
</div>
</div>
<div class="row">
<hr />
<div class="col-lg-4">
<button type="submit" class="btn btn-info">Submit</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
To summarise. All the above “works” in the sense a page is displayed when url : http://localhost:8000/polls/p2vote/X/ is entered in the browser and “X” is the id of the question , extracting data from the model: CC_questions. Also, on the page are input boxes created by the form, VoteForm, that allow data to be entered into table/model CC_Resp_noFK.
However, what I want to do is NOT offer Q_ID as an input field in the page, but instead populate it with the value from variable {{ var_name.id }}. I can’t work out whether I need to modify the vote.html template in some way, particularly the line:
<label for="Q_ID">Question ID</label>
{% render_field form.Q_ID rows="1" class="form-control" %} << change this ??
or the view, somewhere around form.save() ??
def p2vote(request,q_id):
#next line has been copied from CC_quest view to get Question data
CC_question = get_object_or_404(CC_Questions, pk=q_id)
#
if request.method == 'POST':
form = VoteForm(request.POST)
if form.is_valid():
form.save() << Somewhere around here ??
return redirect('/polls/p2')
else:
formV = VoteForm()
#context = {'form' : formV}
# return render(request, 'pollapp2/vote.html', context)
# following return tries to send question record into vote.html template
return render(request, 'pollapp2/vote.html', {'var_name':CC_question,'form' : VoteForm()})
Step 1: Delete Q_ID from VoteForm.
class VoteForm(forms.ModelForm):
class Meta:
model = CC_Resp_NoFK
fields = ['Person_ID', 'Test_date', 'Response_value']
Step 2: Add Q_ID after check if the form is valid and before save the object.
def p2vote(request,q_id):
#next line has been copied from CC_quest view to get Question data
CC_question = get_object_or_404(CC_Questions, pk=q_id)
if request.method == 'POST':
form = VoteForm(request.POST)
if form.is_valid():
item = form.save(commit=False)
item.Q_ID = q_id
item.save()
return redirect('/polls/p2')

''TypeError at /user expected string or bytes-like object'' on submitting the for in django?

When I submitting the form in django it is giving error ''TypeError at /user expected string or bytes-like object''.
This is my staff models
class staff(models.Model):
id = models.AutoField
name = models.CharField(max_length=250)
role = models.CharField(max_length=250)
salary = models.CharField(max_length=250)
address = models.CharField(max_length=250)
number = models.CharField(max_length=250)
date = models.DateField()
This is my user views.
def user(request):
if request.method == "POST" :
name = request.POST['name']
role = request.POST['role']
salary = request.POST['salary']
address = request.POST['address']
number = request.POST['number']
date = DateTimeField()
ins = staff(name=name, role=role, salary=salary, address=address, date=date, number=number)
ins.save()
staffs = staff.objects.all()
return render(request, "salary/user.html", {'staff': staffs})
and this is form of template user.html
<form class="forms-sample" action="/user" method="post">
{% csrf_token %}
<div class="form-group row">
<label for="exampleInputUsername2" class="col-sm-3 col-form-label">Name:</label>
<div class="col-sm-9">
<input type="text" name="name" id="name" class="form-control" id="exampleInputUsername2" placeholder="Username">
</div>
</div>
<div class="form-group row">
<label for="exampleInputUsername2" class="col-sm-3 col-form-label">Role:</label>
<div class="col-sm-9">
<input type="text" name="role" id="role" class="form-control" id="exampleInputUsername2" placeholder="Role">
</div>
</div>
<div class="form-group row">
<label for="exampleInputUsername2" class="col-sm-3 col-form-label">Salary:</label>
<div class="col-sm-9">
<input type="text" name="salary" id="salary" class="form-control" id="exampleInputUsername2" placeholder="Salary">
</div>
</div>
<div class="form-group row">
<label for="exampleInputUsername2" class="col-sm-3 col-form-label">Address:</label>
<div class="col-sm-9">
<input type="text" name="address" id="address" class="form-control" id="exampleInputUsername2" placeholder="Address">
</div>
</div>
<div class="form-group row">
<label for="exampleInputUsername2" class="col-sm-3 col-form-label">Mobile no.:</label>
<div class="col-sm-9">
<input type="text" name="number" id="number" class="form-control" id="exampleInputUsername2" placeholder="Mobile no.">
</div>
</div>
<button type="submit" class="btn btn-primary mr-2">Submit</button>
<button class="btn btn-dark">Cancel</button>
</form>
I am new in django and i not know what the problem is.
Thanks for helping in advance.
It makes no sense to pass a reference to the AutoField model field in your model, you should construct a field, so:
class staff(models.Model):
id = models.AutoField()
# &vellip;
as for the date field, you can work with auto_now_add=True [Django-doc] to automatically fill in the current day:
class staff(models.Model):
# &vellip;
date = models.DateField(auto_now_add=True)
then this can be omitted while constructing a staff object:
def user(request):
if request.method == "POST" :
name = request.POST['name']
role = request.POST['role']
salary = request.POST['salary']
address = request.POST['address']
number = request.POST['number']
# no date=… &downarrow;
ins = staff.objects.create(name=name, role=role, salary=salary, address=address, number=number)
ins.save()
staffs = staff.objects.all()
return render(request, "salary/user.html", {'staff': staffs})
It might however be better to work with Django forms to validate, clean and fill in data from a POST request.
Note: In case of a successful POST request, you should make a redirect
[Django-doc]
to implement the Post/Redirect/Get pattern [wiki].
This avoids that you make the same POST request when the user refreshes the
browser.
Note: Models in Django are written in PascalCase, not snake_case,
so you might want to rename the model from staff to Staff.

Django Multiple Form Processing in same View

I am looking for some assistance in two areas for django forms processing.
I have a class view that overrides post and checks the name of the form in request.POST to determine which form has been submitted. based on the form submitted, I perform the appropriate actions for that form and save to the model. That part works correctly. I am not using a model form, just a custom html form created in the template with input fields. See the below view and html for reference. Is this the correct way to handle this or is there a best practice I should be following that makes use of model forms? Code seems a bit heavy to me and non-standardized, like there should be a better way...
Being that I am not using model forms, the error processing has me a little confused. How do you handle error processing on a normal html form that does not make use of django model forms? See below in the view where notated # ERROR HANDLING FOR FORM NEEDED in code, specifically on the username field which is unique and validated on the model level.
views.py
class ProfileView(View):
def get(self, request, *args, **kwargs):
if request.method == "GET":
# load profile data...
def post(self, request, *args, **kwargs):
if request.method == "POST":
# check if profile_form submitted
if 'profile_form' in request.POST:
# get user form data
profile_data = request.POST.dict()
# get current user profile
user_profile = Profile.objects.get(my_user=request.user)
# check username entry against current
if user_profile.username == profile_data['username']:
user_profile.country = profile_data['country']
user_profile.display_location = profile_data['display_location']
user_profile.organization_name = profile_data['organization']
user_profile.save(update_fields=['country', 'display_location','organization_name'])
#send success message to page
messages.success(request, "Success: Profile was updated.")
else:
try:
user_profile.username = profile_data['username']
user_profile.country = profile_data['country']
user_profile.display_location = profile_data['display_location']
user_profile.organization_name = profile_data['organization']
user_profile.save(update_fields=['username', 'country', 'display_location','organization_name'])
#send success message to page
messages.success(request, "Success: Profile was updated.")
except:
# unique constraint error on username
# ERROR HANDLING FOR FORM NEEDED
# check if user_name_form submitted
if 'user_name_form' in request.POST:
# get user form data
user_data = request.POST.dict()
# get current user
user = MyUser.objects.get(email=request.user)
user.first_name = user_data['first_name']
user.last_name = user_data['last_name']
user.save(update_fields=['first_name', 'last_name'])
# send success message to page
messages.success(request, "Success: Name was updated.")
# Return Profile page view with updated data
return HttpResponseRedirect(reverse('profile'))
html
<!--form-->
<form id="profile" class="small" method="POST" action="{% url 'profile' %}">
{% csrf_token %}
<!--Username-->
<label for="username">Username <span style="font-style: italic;">(create a unique display name that will appear to other users on the site)</span></label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="username">#</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="username" name="username" value="{% if profile and profile.username is not None %}{{ profile.username }}{% endif %}">
</div>
<hr>
<p>Tell us where you are from!</p>
<!--Country State/Province City Select-->
<div class="form-group">
<select name="country" class="form-control mb-3" id="country">
<option value="">Select Country...</option>
{% for country in countries %}
{% if profile.country == country.name %}
<option value="{{ country.name }}" id="{{ country.code }}" selected>{{ country.name }}</option>
{% else %}
<option value="{{ country.name }}" id="{{ country.code }}">{{ country.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<hr>
<p>Enter your profile display location <i>(ie. City, State, Province, Region...)</i></p>
<input type="text" class="form-control" id="display_location" name="display_location" placeholder="Based in..." value="{% if profile and profile.display_location is not None %}{{ profile.display_location }}{% endif %}">
<hr>
<p>Do you belong to an organization?</p>
<input type="text" class="form-control" id="organization" name="organization" placeholder="Organization Name" value="{% if profile and profile.organization_name is not None %}{{ profile.organization_name }}{% endif %}">
<hr>
<button type="submit" class="btn btn-primary" name="profile_form" value="profile_form">Save</button>
</form>
This can be tricky to do, so at DjangoCon a few years ago, we built a Django app to help. Have a look:
https://github.com/kennethlove/django-shapeshifter
As a solution to this problem I was able to get to, see the post here for a way to do this without a 3rd party app.

i want to insert data in a new model after calling is through a post method , how do in do that when a i call it through the template?

models.py
from django.db import models
class booking(models.Model):
fname=models.CharField( max_length=50)
lname=models.CharField( max_length=50)
email=models.EmailField(max_length=254)
city=models.CharField(max_length=50)
state=models.CharField(max_length=50)
pin=models.IntegerField()
def __str__(self):
return self.fname
class approved(models.Model):
fname=models.CharField( max_length=50)
lname=models.CharField( max_length=50)
email=models.EmailField(max_length=254)
city=models.CharField(max_length=50)
state=models.CharField(max_length=50)
pin=models.IntegerField()
def __str__(self):
return self.fname
views.py
def adminp(request):
if 'form_rejected' in request.POST and request.method=="POST":
print("Went into reject")
p=booking.objects.filter(id=request.POST.get('object_id','')).delete()
print(p)
elif 'form_approved' in request.POST and request.method=="POST":
print("went in approve")
fname= booking.objects.filter(fname=request.POST.get('object_fname','')).values_list('fname')
lname= booking.objects.filter(lname=request.POST.get('object_lname','')).values_list('lname')
email= booking.objects.filter(email=request.POST.get('object_email','')).values_list('email')
city= booking.objects.filter(city=request.POST.get('object_city','')).values_list('city')
state= booking.objects.filter(state=request.POST.get('object_state','')).values_list('state')
pin= booking.objects.filter(pin=request.POST.get('object_pin','')).values_list('pin')
app= approved(fname=fname,lname=lname,email=email,city=city,state=state,pin=pin)
app.save()
print(fname,pin)
x=booking.objects.all()
params={'pro': x}
return render(request,'dbms/adminpanel.html',params)
template
<form action="" method="POST">
{% csrf_token %}
<div class="col"><p>Firstname: {{i.fname}}</p></div>
<div class="col"><p>Lastname: {{i.lname}}</p></div>
<div class="col"><p>Email: {{i.email}}</p></div>
<div class="col"><p>City: {{i.city}}</p></div>
<div class="col"><p>Pin: {{i.pin}}</p></div>
<input type="hidden" name="object_fname" value="{{ i.fname }}">
<input type="hidden" name="object_lname" value="{{ i.lname }}">
<input type="hidden" name="object_email" value="{{ i.email }}">
<input type="hidden" name="object_city" value="{{ i.city }}">
<input type="hidden" name="object_state" value="{{ i.state }}">
<input type="hidden" name="object_pin" value="{{ i.pin }}">
<input class="btn btn-success mx-2" name="form_approved" type="submit" value="Approve">
<input type="hidden" name="object_id" value="{{ i.id }}">
<input class="btn btn-danger mx-2" name="form_rejected" type="submit" value="Reject"> <!--Added attribute name="form_rejected"-->
OUTPUT after printing output of fname and pin:
went in approve
<QuerySet [('snaTYE',)]> <QuerySet [(939393,)]>
when I print fname just to check it gives me a queryset which can't be inserted, so how do either insert the following in approved database or how do get only value in the queryset.
Use the value of the hidden field object_id to get the booking instance. You don't need the other hidden fields. As you discovered, booking.objects.filter() gives you a queryset. Use booking.objects.get() to get a single instance. Not that this raises an exception if no database entry matching your query exists. Then use the values from the booking instance to create the approved instance.
try:
booking_obj = booking.objects.get(id=request.POST.get('object_id')
approved_obj = approved.objects.create(
fname=booking_obj.fname,
lname=booking_obj.lname,
email=booking_obj.email,city=booking_obj.
city,
state=booking_obj.state,
pin=booking_obj.pin
)
except booking.DoesNotExist:
# handle error somehow
Two remarks:
check out the documentation on form handling it can make live much easier.
it is a common convention to capitalize model names (like all class names), e.g. class Booking. I'd suggest you stick to this convention, unless you have a good reason not to.

Django How do i pass the url parameter with the form button?

Hi i am Newbie in django i read django documentation but i had made a url with parameteres i want to book a car . for booking i need car id and driver id . after redirect to my booking page . my book now button is not sending the driver id and car id . please help me.
for example.
i am having a John as a Driver , and he click on Audi To book . after getting his url i want to save it to my booking database . after click on button in my html "book now" it doesnt render to next page book a car and dont get the car id and driver id.
please help me.
Sorry for my english . if didnt understand please let me know in comments ill more explain to you and share more content . i am just beginner in field so just learning .
Views
#csrf_protect
def rentacar_car(request, car_id,driver_id):
try:
args['car'] = Car.objects.get(id__exact=car_id)
args['driver_id'] = driver_id
except:
args['car'] = None
args['driver_id'] = None
if args['car'] is not None:
template = Template.objects.get(template_default__exact=1)
return render(request, template_page, args)
else:
return HttpResponseRedirect('/rentacar/list/')
def rentacar_booking(request):
template = Template.objects.get(template_default__exact=1)
template_page = template.template_alias + str("/rentacar/rentacar_booking_form.html")
menu_config_list = MenuItemRentacarList.objects.all()[0]
menu_config = MenuItemRentacarList.objects.get(id=menu_config_list.id)
args['main_menu'] = MenuMenu.objects.get(id__exact=template.template_main_menu_id)
args['menu_items'] = MenuItem.objects.filter(
menu_item_menu=args['main_menu'],
menu_item_published=1,
)
args['current_menu_item'] = menu_config.menu_item_rentacar_list_menu_item
all_modules = Module.objects.filter(
module_show_option__exact='all',
module_published=1
)
selected_modules = Module.objects.filter(
module_show_option__exact='selected',
module_published=1,
module_menu_item=args['current_menu_item']
)
excluded_modules = Module.objects.filter(
module_show_option__exact='except',
module_published=1,
).exclude(
module_menu_item=args['current_menu_item']
)
args['modules'] = list(chain(all_modules, selected_modules, excluded_modules))
try:
args['car'] = Car.objects.get(id__exact=request.POST.get('car_id'))
args['driver'] = Driver.objects.get(id__exact=request.POST.get('driver_id'))
except:
args['car'] = None
args['driver'] = None
if args['car'] is not None:
return render(request, template_page, args)
else:
return HttpResponseRedirect('/rentacar/list/')
else:
return HttpResponseRedirect('/')
Templates
rentacar_book_form
<div class="row">
<div class="medium-6 small-12 columns">
<label>
Book Start Date <br>
<input type="date" name="book_booking_start_date" required>
</label>
</div>
<div class="medium-6 small-12 columns">
<label>
Book End Date <br>
<input type="date" name="book_booking_end_date" required>
</label>
</div>
</div>
<hr>
<input type="submit" class='button large primary' value="Book {{ car.car_brand.brand_name }} {{ car.car_name }}">
</div>
</div>
<input type="text" name="book_booking_car_car" value="{{ car.id }}" class="hidden">
<input type="text" name="book_booking_driver_driver" value="{{ driver.id }}" class="hidden">
rentacar_car_car
<form action="/rentacar/book-a-car/" method="post">
{% csrf_token %}
<input name="car_id" type="text" value="{{ car.id }}" class="hidden" required>
<input name="driver_id" type = 'text' value="{{ driver.id }}" class = 'hidden' required>
<button type="submit" class="button primary uppercase centered full-width">
Book now!
</button>
</form>
urls.py
url(r'^rentacar/book-a-car/$', extension_views.rentacar_booking),
url(r'^rentacar/list/(\d+)/$', extension_views.rentacar_list),
url(r'^rentacar/car/(\d+)/driver/(\d+)/$', extension_views.rentacar_car),
If you just want to get the values from hidden inputs just do this.
In method rentacar_car type:
car_id = request.GET.get('car_id')
driver_id = request.GET.get('driver_id')
print(car_id)
print(driver_id)
And since you are getting the values from those inputs you have to change method of form to GET.