This is my url.py
app_name = 'springcity'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^home/$', views.home, name='home'),
url(r'^portal/$', views.portal, name='portal'),
url(r'^ajax/cutlist/$', views.cutList, name='cutlist'),
]
This is my views.py
def home(request):
if request.method == "POST":
if 'Search' in request.POST:
modelIn = request.POST['mid']
db = get_object_or_404(PDetails, model=modelIn)
form = calcForm()
form.fields["stc"].initial = db.stc
form.fields["ocv"].initial = db.ocv
form.fields["mppv"].initial = db.mppv
form.fields["nvtc"].initial = db.nvtc
form.fields["mmppc"].initial = db.mmppc
form.fields["maxov"].initial = db.maxov
form.fields["maxc"].initial = db.maxc
args = {
'calcForm': form,
}
return render(request, 'calculator/portal.html',args)
else:
if 'MInput' in request.POST:
form = calcForm()
args = {
'calcForm': form,
}
request.method = "GET"
return render(request, 'calculator/portal.html',args)
else:
if request.method == "GET":
objectlist = Brand.objects.all().order_by('brand')
args = {
'objectlist': objectlist,
}
return render(request, 'calculator/home.html',args)
Then this is my html that I start off with.
{% extends 'calculator/index.html' %}
{% block title %} Home {% endblock %}
{% block link %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'calculator/css/home.css' %}"/>
<script type="text/javascript" src="{% static 'calculator/js/home.js' %}"></script>
{% endblock %}
{% block main %}
<form action="{% url 'springcity:home' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="row center">
<div class="input-field col s3 offset-s4">
<select id="brandID">
<option value="">Choose Company</option>
{% for brand in objectlist %}
<option value='{{brand.brand}}'>{{ brand.brand }}</option>
{% endfor %}
</select>
<!--<label>Choose Company</label>-->
</div>
</div>
<div class="row center">
<div id="modelRow" class="input-field col s3 offset-s4" hidden>
<select name="mid" id="modelID">
<option value="">Choose Model</option>
</select>
<!--<label>Choose Model</label>-->
</div>
</div>
<div class="row center">
<div class="col s3 offset-s4">
<div class="button-center">
<button type="submit" class="btn waves-effect waves-light" name="Search" id="search">Search</button>
</div>
</div>
</div>
<div class="row center">
<div class="col s3 offset-s4">
<div class="button-center">
<button type="submit" class="btn waves-effect waves-light" name="MInput" id="manual_input">Manual Input</button>
</div>
</div>
</div>
</form>
{% endblock %}