Add search to my blog app

17 views
Skip to first unread message

sunday honesty

unread,
May 20, 2020, 12:15:03 PM5/20/20
to Django users
Hello everyone! I have got a question. I am a Django beginner trying to build my first web app after completing a book.

I made an app I called developers forum where authenticated users can post something like question or code achievement and another can comment in form of answer.
I want to add a search functionality which was not covered in the tutorial.
I browsed out and found how I could add the search but the search results will be displayed to a designated urls created for the purpose. I want to be able to redirect the searcher to the exact post containing the keyword they have typed in the search form with the text highlighted. How can I achieve that... If you need any pieces of my code to be able to help me, be kind to ask me; I'll post a link to where you can find it.
Thanks in advance.

Vishesh Mangla

unread,
May 20, 2020, 12:26:11 PM5/20/20
to django...@googlegroups.com

Hi if you want a search bar you need javascript which will do the dynamic stuff. Add an event listener to you <input type=”search”> of html and use “change” as the event. Then you need to insert and remove elements on the DOM based on the text in the search box. For more info ask on  https://webchat.freenode.net/ in the #javascript.

 

Sent from Mail for Windows 10

--

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 django-users...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cdbf7038-480e-446f-aeac-e079ad575e47%40googlegroups.com.

 

sunday honesty

unread,
May 20, 2020, 12:28:23 PM5/20/20
to django...@googlegroups.com
I don't know JavaScript

Vishesh Mangla

unread,
May 20, 2020, 12:55:15 PM5/20/20
to django...@googlegroups.com

Then you have a better option to learn react(a frontend framework for javascript). You cannot do dynamic stuff on the web without using javascript.

Ali Ahammad

unread,
May 20, 2020, 1:01:41 PM5/20/20
to Django users
At first you should make search search template where you should put what and how you want display

Then you should write a views.py function where you should use
query=request.GET[‘queer’]
Object_list=Post.objects.filter(title__icontains=query)
*same for the content If you want and then you should use union*
Return render(request,’search.html’,{ ‘object_list’:object_list,’query’:query})

Then in the sign.html use ur home.html or anything and write according to your requirement

You don’t need to use java

Vishesh Mangla

unread,
May 20, 2020, 1:05:09 PM5/20/20
to django...@googlegroups.com

Javascript it that needs to be done dynamically otherwise redirect()

 

Sent from Mail for Windows 10

 

From: Ali Ahammad
Sent: 20 May 2020 22:32
To: Django users
Subject: Add search to my blog app

 

At first you should make search search template where you should put what and how you want display

--

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 django-users...@googlegroups.com.

Vishesh Mangla

unread,
May 20, 2020, 1:05:41 PM5/20/20
to django...@googlegroups.com

Or one thing you can do w/o javascript, that is send a post request to the server through a form and then redirect to a view with a blog matching that search query.

 

Template:

 

<form method=”POST >

{{csrf_token}} //see the correct template tag

<input type=”search” name=”search>

<button  type=”submit”>Submit<button>

</form>

 

Views:

def index(request):

    if request.method ==”POST”:

        search_query = request.POST[“search”]

        //Suppose search query is blog_1

       If search_query[-1] == 1:

           return httpResponse(“blog1”)

    return //default index.html 

sachin chaurasiya

unread,
May 20, 2020, 5:49:51 PM5/20/20
to django...@googlegroups.com
From which book you have had learnt django

--
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 django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages