I have set up a query-able database using django 1.8 and sqlite. However I cannot seem to figure out how to get the output from when I query the database. I have two HTML files- input.html (with a text box and submit button to insert data to query the sqlite database) and output.html (which will return the according data from the database). I am referencing these files and calling the output and input functions as follows:
The 'views' files for input and output are in separate directories.
Input within /freezer/views.py
def table(request):
form=PersonID()
context={
"form": form,
}
if form.is_valid():
form.save()
context={
"title": "Thank you"
}
return render (request, "temp.html", context)
Output within /mysite/views.py
def results(request):
Louis=Person.objects.get('Louis')
context={
'Louis': Louis
}
return render (request, "output.html", context)
models.py contains a class "Person" with fields "Firstname" and "Lastname", 'Louis' and 'Pasteur' were input into these fields with sqlite. I would prefer to be able to input a first name and return the accompanying last name as opposed to what I have above.
Furthermore in my actual html files I have:
input.html
<form id="herv" method="POST" action="#######">{% csrf_token %}
<th>Sequence Input</th>
<textarea id=�textareainput� name =�textareainput� rows=10 cols=50>
Input sequence here
</textarea>
<tr>
<INPUT NAME="confirm" TYPE="SUBMIT" ONCLICK ="clicked(event);" VALUE="Confirm">
</tr>
{{title}} # to print 'Thank You'
</form>
What do I set action equal to in order to query the database and go to the output page after printing "Thank you"? Should this process involve modification of the "SUBMIT" button?
as for output.html, simply:
<html>
{{Louis}}
</html>
So overall my questions are:
-
How do set up a system such that I can query one field to retrieve another from a corresponding row (should this involve a 'HttpRedirect' command)?
-
Can I keep the views.py's in separate directories so long as I reference their paths in 'urls.py' properly?
-
What do I set 'action=' in order to query the database with the given input?
Aucun commentaire:
Enregistrer un commentaire