Hey!


If I submit 'http://localhost:8000/item/2/' to the address bar, I get the 
desired result, which is a rendering of item_detail.html with its item 
variables filled.


But when I try to pass the ‘2’ via a form, I only get the html without 
rendering (and instead displaying in the console upon a console.log.


How can I use a form to get the initial result? And is there an easiest way 
to do this?


I've added the code below... thanks.


INDEX.HTML

<form id="form">
Item Name:<br><input id="entry" type="text"><br><input type="submit" 
value="Submit"></form> 


MAIN.JS

var form=$("#form")
$(document).on("submit", "#form", function (e) {
e.preventDefault();var term = $("#entry").val()  var query="/item/"+term
$.ajax({ 
    type: 'GET',
    url: query, }).done(function(response) {
    console.log(response)}) })


URL.PY

url(r'^item/(?P<id>\d+)/', views.item_detail, name='item_detail'),


VIEWS.PY

def item_detail(request, id): 
   try: 
       item = Item.objects.get(id=id)
   except Item.DoesNotExist: 
       raise Http404("This item doesn't exist")

   return render(request, 'inventory/item_detail.html',{
       'item': item,
   })


MODELS.PY

  class Item(models.Model):
      title = models.CharField(max_length=200)
      description = models.TextField()
      amount = models.IntegerField()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e88d027e-f1b3-446e-a759-09a37bdd934f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to