Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

python 3.x - Online result search aplication first html page should render the form and second page will show the data. Help Appricated?

Django, I have two HTML pages first is index.html which shows the home page along with the search field and the second HTML form is the result which shows the desired result which is search by the user. I have already written code that is working fine on only one page but I want to redirect the home page once the user fillup the details it should go to the next page called result.html.

modles.py

from django.db import models
from django.utils.encoding import smart_text
from multiselectfield import MultiSelectField

# Create your models here.




class ResultQuery(models.Model):
    os_choice = (
        ('Windows 10', 'Windows 10'),
        ('Windows 8', 'Windows 8'),
        ('Linux', 'Linux'),
    )
    operating_system = models.CharField(max_length=30, blank=True, null=True, choices=os_choice)

    level = models.CharField(max_length=30)
    program = models.CharField(max_length=30)
    semester = models.CharField(max_length=20)
    exam_year = models.IntegerField()
    institute = models.CharField(max_length=4)
    reg_no = models.CharField(max_length=50)
    symbol_num = models.IntegerField()
    student_name = models.CharField(max_length=50)
    dob = models.DateField()
    sgpa = models.TextField()
    result = models.CharField(max_length=40)
    name = models.CharField(max_length=30)
    subject1_code=models.CharField(max_length=40)
    subject1_title=models.CharField(max_length=40)
    subject1_credit_hour=models.TextField()
    subject1_grade_point=models.TextField()
    subject1_grade=models.TextField()
    subject1_remarks=models.CharField(max_length=20, null=True, blank=True)

    subject2_code = models.CharField(max_length=40)
    subject2_title = models.CharField(max_length=40)
    subject2_credit_hour = models.TextField()
    subject2_grade_point = models.TextField()
    subject2_grade = models.TextField()
    subject2_remarks = models.CharField(max_length=20, null=True, blank=True)

    subject3_code = models.CharField(max_length=40)
    subject3_title = models.CharField(max_length=40)
    subject3_credit_hour = models.TextField()
    subject3_grade_point = models.TextField()
    subject3_grade = models.TextField()
    subject3_remarks = models.CharField(max_length=20, null=True, blank=True)

    subject4_code = models.CharField(max_length=40)
    subject4_title = models.CharField(max_length=40)
    subject4_credit_hour = models.TextField()
    subject4_grade_point = models.TextField()
    subject4_grade = models.TextField()
    subject4_remarks = models.CharField(max_length=20, null=True, blank=True)

    subject5_code = models.CharField(max_length=40)
    subject5_title = models.CharField(max_length=40)
    subject5_credit_hour = models.TextField()
    subject5_grade_point = models.TextField()
    subject5_grade = models.TextField()
    subject5_remarks = models.CharField(max_length=20, null=True, blank=True)

    subject6_code = models.CharField(max_length=40)
    subject6_title = models.CharField(max_length=40)
    subject6_credit_hour = models.TextField()
    subject6_grade_point = models.TextField()
    subject6_grade = models.TextField()
    subject6_remarks = models.CharField(max_length=20, null=True, blank=True)

    def __str__(self):
       return smart_text(self.name)

forms.py

from django import forms
from search.models import ResultQuery
from django.forms import MultipleChoiceField, ChoiceField, Form
class ResultForm(forms.Form):
      Reg_No = forms.CharField(label="Registration Number")
      Name = forms.CharField(label="Your Name")
      OS = forms.ChoiceField(choices=ResultQuery.os_choice)

views.py

from django.shortcuts import render

# Create your views here.
from django.shortcuts import render
from .forms import ResultForm
from .models import ResultQuery



def home(request):
    form=ResultForm(request.POST or None)
    template_name = "index.html"
    context = {"form": form}
    if form.is_valid():
        objects = ResultQuery.objects.filter(reg_no=form.cleaned_data['Reg_No'], name=form.cleaned_data['Name'], operating_system=form.cleaned_data['OS'])
        context['objects'] = objects

    return render(request, template_name, context)

index.html

{% load static %}
{% load crispy_forms_tags %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>online</title>

    <meta name="description" content="Source code generated using layoutit.com">
    <meta name="author" content="LayoutIt!">

    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/style.css' %}" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">



    

  </head>
  <body>

    <div class="container-fluid">
        <div class="row" id="top">
            <div class="col-md-12">
            </div>
        </div>
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-4" id="h4">
                </div>
                <div class="col-md-4" id="logo">
                    <img src="img/logo.png" alt="" srcset="">
                    <br>
                    <h1 class="a">Saj University School of Management</h1>
                </div>
                <div class="col-md-4" id="h4">
                    <h4>Online Result Form</h4>
                </div>
            </div>
            <div class="row" id="top">
                <div class="col-md-12">
                </div>
            </div>
            
            <br>
            <div class="row">
                <div class="col-md-4">
                    <form action="" method="POST">

                         {% csrf_token %}
                            {{form|crispy}}
                        <select class="amrit" name="cars" id="cars">
                            <optgroup>
                            <option value="none" selected disabled hidden>Select an Institution</option>
                            <option value="management">School of Management</option>
                            <option value="engineering">Faculty of Engineering</option>
                            <option value="science">Faculty of Science and Technology</option>
                        </optgroup>
                          </select>
                          <br>
                          <select class="amrit" name="cars" id="cars">
                            <optgroup>
                            <option value="none" selected disabled hidden>Select a level</option>
                            <option value="management">Bachelor</option>
                            <option value="engineering">Master</option>
                        </optgroup>
                        </select>
                        <br>
                        <select class="amrit" name="cars" id="cars">
                            <optgroup>
                            <option value="none" selected disabled hidden>Select a Program</option>
                            <option value="management">BBA</option>
                            <option value="engineering">MBA</option>
                            <option value="engineering">BHM</option>
                        </optgroup>
                        </select>
                        <br>
                        <select class="amrit" name="cars" id="cars">
                            <optgroup>
                            <option value="none" selected disabled hidden>Select a Semester</option>
                            <option value="management">1st</option>
                            <option value="engineering">2nd</option>
                            <option value="engineering">3rd</option>
                            <option value="third">4th</option>
                            <option value="firth">5th</option>
                            <option value="sixth">6th</option>
                            <option value="seventh">7th</option>
                            <option value="eight">8th</option>
                        </optgroup>
                        </select>
                        <br>
                        <input type="search" placeholder="Exam Year" name="year" id="year">
                        <br>
                        <input type="search" placeholder="Symbol Number" name="year" id="year">
                        <br>
                        <input type="search" placeholder="DOB(YYYY-MM-DD)" name="dob" id="year">
                        <br>
                        <button type="submit" id="year" name="search">Search</button>
                      </form> 
                    
                </div>
                <div class="col-md-4" id="sliderbor"> <!--slider start-->
                    <div class="hero">
                    <div class="w3-content w3-display-container">
                        <img class="mySlides" src="{% static 'img/inaki-del-olmo-NIJuEQw0RKg-unsplash.jpg' %}" style="width:100%">
                        <img class="mySlides" src="{% static 'img/inaki-del-olmo-NIJuEQw0RKg-unsplash.jpg' %}" style="width:100%">
                        <img class="mySlides" src="{% static 'img/inaki-del-olmo-NIJuEQw0RKg-unsplash.jpg' %}" style="width:100%">
                        <img class="mySlides" src="{% static 'img/inaki-del-olmo-NIJuEQw0RKg-unsplash.jpg' %}" style="width:100%">
                      
                        <button class="w3-button w3-black w3-display-left" onclick="plusDivs(-1)">&#10094;</button>
                        <button class="w3-button w3-black w3-display-right" onc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...