[Answered ]-How to get data from get method

1👍

You can send data in the URL:

for example say we have an url like this:

http://localhost:8000/hi?id="bye"

You can obtain the data in Django from two ways:

request.GET['id']

or

request.GET.get('id', 'default value')

1👍

A better, more search engine friendly way might be to use keyword arguments in your URL, and have a slug on your book object.

getBooksDetails.html

<a href="getBookDetails" style="text-decoration: none">
<a href="{% url 'book' book.slug %}>{{ book.title.upper }}</a>
</a>

slug attribute on Book model

from django.utils.text import slugify

class Book(Model):
    ...
    slug = slugify(self.title)
    ...

urls.py

urlpatterns = patterns('',
                       (r'^index', 'views.index'),
                       (r'getBookDetails/(?P<slug>\w+/', 'views.getBookDetails'),
)

And you can access the title-slug in your view either by using **kwargs if you’re using class based views, or by adding slug=None to your view definition if you’re using function based views.

Leave a comment