Тёмный

Create A Search Bar - Django Wednesdays #9 

Codemy.com
Подписаться 235 тыс.
Просмотров 98 тыс.
50% 1

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 147   
@Codemycom
@Codemycom 3 года назад
▶️ Watch Entire Django Wednesdays Playlist ✅ Subscribe To My RU-vid Channel: bit.ly/35Xo9jD bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN ▶️ Get The Code bit.ly/3sJpeV6
@ahgpy
@ahgpy 3 года назад
man ur awesome this is not clickable Read more...
@deki90to
@deki90to 3 года назад
If someone have problem like me with printing foreign object to the template, solution is (foreign_object__object_name__icontains=search)
@michaelkovnick
@michaelkovnick 2 года назад
At 10:30 in this video venues = Venue.objects.filter(name__contains=searched) provided a case-sensitive search. Looking at the docs, it appears I need to add an "i" before contains to make it case-insensitive, resulting in: venues = Venue.objects.filter(name__icontains=searched). Perhaps this was a change in Django 4?
@jothamprince8765
@jothamprince8765 2 года назад
thanks a lot bro, was stuck on that bug the whole day, could u perhaps send a link to that part of the documentation so that i can read and learn more
@johnsolly
@johnsolly 2 года назад
If you want to search across multiple fields in the post/venue model (Like the content or the title), you can do it like this: from django.db.models import Q filtered_posts = Post.objects.filter(Q(content__contains=searched) | Q(title__contains=searched)) The pipe character, '|' means 'OR' so you can search across both the content and the tile at the same time!
@amangautam1779
@amangautam1779 2 года назад
What is Q here?
@horger89
@horger89 2 года назад
@@amangautam1779 stands for query if I'm not mistaken
@Charoiz
@Charoiz Год назад
And if someone needs to search through Foreignkeys for example for events, you would add Filter(Q(Venue__address__contains= searched)
@VladyslavHoncharov-c6r
@VladyslavHoncharov-c6r Год назад
Thank you a lot!!! I lost like 3 hours to find this info. Your coment helped me.
@johnsolly
@johnsolly Год назад
I just added a new video to my channel about adding a "smart search" for your Django app. It's a lot more powerful than the Q search I mention in this comment.
@alexanderzittel8629
@alexanderzittel8629 3 года назад
Thanks John for your very helpful videos! I like them very much! If someone has the same problem with the views.py as me: I had to change the line to: searched = request.POST.get('searched') The both solutions shown in the video didn´t work for me.
@sathyanarayanan99
@sathyanarayanan99 3 года назад
At 8:11, you use either request.POST['param'] or request.POST.get('param'). It's parentheses whenever we use a getter.
@salmanalsaffar8040
@salmanalsaffar8040 3 года назад
thanks man, I was struggling
@harshivthakkar5734
@harshivthakkar5734 2 года назад
Thanks man later worked for me
@sinistergeek
@sinistergeek Год назад
Live saver! thanks !
@DookyButter
@DookyButter 2 года назад
@8:05 The reason brackets work here is because he is indexing the dictionary through bracket notation, i.e. request.POST['foo']. If you use the get method of a dictionary, THEN you use parentheses, i.e. request.POST.get('foo'). That's why people would see a difference. Both are acceptable.
@muvi9230
@muvi9230 3 года назад
Thanks for video! but I get "" that , how can i fix this?
@Codemycom
@Codemycom 3 года назад
rewatch the video and try to figure out what you did differently
@kitewaves
@kitewaves Год назад
Thanks for great tutorials John - For the "search" field, would you advise to "Clean" it first before using it in the view to avoid XSS?
@Codemycom
@Codemycom Год назад
I suppose so...
@timw3447
@timw3447 2 года назад
venues = Venue.objects.filter(name__contains=searched) -- was only showing case sensitive results for me after some searching: venues = Venue.objects.filter(name__icontains=searched) fixed that (note name__icontains was the change)
@PatrickAmone
@PatrickAmone 6 месяцев назад
Actually this is my first comment in RU-vid. I am a software developer in other languages, so I embarked to learn django, which i have been reading documentation, but when i started following your videos, I can proudly say that you deserve award. Your lecturer to say, is straight forward and on point. Good job.
@Codemycom
@Codemycom 6 месяцев назад
Thanks! Glad you enjoy the videos!
@kittyrah2800
@kittyrah2800 Год назад
Is there a way to prevent the 'confirm form resubmission' popup from the search bar form only?
@stromigaming7970
@stromigaming7970 8 месяцев назад
Is that also workable in images in model?
@asce313
@asce313 3 года назад
Oh wow, thanks John, was waiting for this video for quite sometime 😅
@Codemycom
@Codemycom 3 года назад
Hope you enjoyed it!
@midomezo9231
@midomezo9231 3 года назад
views get the data i can print it in terminal but it doesn't display it in template, tried everything def SearchView(request): if request.method == 'POST': searched = request.POST.get('searched') print(searched) return render(request, 'search/search.html', { searched:'searched' }) else: return render(request, 'search/search.html', {}) you searched for {{ searched }} or {% if searched %} you searched for {{ searched }} {% else %} You didn't search {% endif %}
@MagicByIzzy
@MagicByIzzy 3 года назад
Love your videos John! I was the 1000th view!
@Codemycom
@Codemycom 3 года назад
Awesome! Thanks for watching!
@sorinbala703
@sorinbala703 Год назад
i get a error like this: Field 'id' expected a number but got 'my search' how can i fix this?
@Codemycom
@Codemycom Год назад
what did you do differently from the video?
@amirrezaasmaeizadeh3435
@amirrezaasmaeizadeh3435 7 месяцев назад
Thanks a lot for the best django learning page 🔥
@Codemycom
@Codemycom 7 месяцев назад
Welcome! Glad you liked it!
@danialazarpanah8875
@danialazarpanah8875 2 года назад
But what should we do if we want the text we have searched stay in the searched bar after doing the search? In this sample the text disappears after clicking the search button
@lorimedicenter4439
@lorimedicenter4439 2 года назад
your video is very fantastic...... coup de chapeau .... absolument dingue.... thank you very much .🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
@Codemycom
@Codemycom 2 года назад
Glad you enjoyed it!
@stachcode9085
@stachcode9085 3 года назад
there are a lot of tutorials in youtube but the secret key to understand a topic is the instructor style. i started to learn basics of django from you and know i started to make some mony from coding and when i get stuck in something i always come back to you videos and i always find the solution. learning from u is alwyas easy and fun thanks man. god bless you
@Codemycom
@Codemycom 3 года назад
Happy to hear it!
@pj-pandaz2385
@pj-pandaz2385 3 года назад
def searchlist(request): if request.method == "POST": search_list= request.POST['search_list'] searchfound = DogRescue.objects.filter(name__icontains= search_list) return render(request,'search.html',{"search_list": search_list, "searchfound": searchfound }) else: return render(request,'search.html',{}) Cannot resolve keyword 'name' into field. Choices are: Behavior, Characteristics, Hero, Hero_id, Location, Message, id .H ow to do please help? Thankyou
@xterminal
@xterminal 2 года назад
The error message you are receiving indicates the DogRescue table does not contain a name field. Substitute the column name where the search should be looking for "name" (e.g., if you want to search on values in the Behavior field, your filter should be "searchfound = DogRescue.objects.filter(Behavior__icontains =search_list)".
@abdullahatif7854
@abdullahatif7854 3 года назад
What about typo's and stuff. Sqlite3 can't deal with typo's and stuff. I was expecting something else. DISAPPOINTED !
@Codemycom
@Codemycom 3 года назад
lol what in the world are you talking about?
@slsantos100
@slsantos100 Год назад
Thank you! very ...very so much. you are saved me...rrrrss
@brittvink8569
@brittvink8569 2 года назад
I keep getting an error if i use filter(id__contains=searched). Any idea how I can solve this? This is the error (1287, "1287: 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead", None). I'm working with a mysql database
@Coffeenoosh-Viral
@Coffeenoosh-Viral Год назад
Hi, have you found any solution to this issue by any chance, I have the same issue...
@imediastv
@imediastv 10 месяцев назад
realy best course for django search
@Codemycom
@Codemycom 10 месяцев назад
thanks!
@partialcoder6386
@partialcoder6386 2 года назад
hello :)
@Codemycom
@Codemycom 2 года назад
Hello
@partialcoder6386
@partialcoder6386 2 года назад
I LOVE YOUR WAY OF TEACHING AND YOUR INTRO
@Codemycom
@Codemycom 2 года назад
@@partialcoder6386 Thanks!
@vensarabhi
@vensarabhi 3 года назад
Eagerly waiting for your videos sir...
@Codemycom
@Codemycom 3 года назад
Thanks for watching!
@aravinths641
@aravinths641 4 месяца назад
I have a case sensitive for characters problem what to do !!!! 😭
@Codemycom
@Codemycom 4 месяца назад
Sorry I don't know what that is...
@aaronlal2676
@aaronlal2676 3 месяца назад
try "icontains" instead of "contains"
@chrz4322
@chrz4322 2 года назад
Did anyone else have trouble getting the two html pages linked??? I've followed this tutorial exactly and when i click the search bar button it doesn't do anything! Any suggestions
@Codemycom
@Codemycom 2 года назад
Then you didn't follow the tutorial exactly. Recheck your code :-)
@dvgpraveen
@dvgpraveen 11 месяцев назад
What data inside the base. Html???
@Codemycom
@Codemycom 11 месяцев назад
just what the video shows...? What's the confusion?
@aykanseper
@aykanseper 2 года назад
Sir, thank you for the videos, you describe everything in perfect detail. But how can we search a name or something else inside of all the tables instead of just one table, in this case Venue. How do I query the entire database, for instance is there a way to change, venues = Venue.objects.filter(name__contains=searched) statement so that users would search the word in the entire database? Thanks again!
@Codemycom
@Codemycom 2 года назад
Sure, pretty sure I have videos on that sort of thing
@kyawmying224
@kyawmying224 9 месяцев назад
Thank you so much your videos are very helpful for people who can't afford for class like me.I am really appreciate you
@Codemycom
@Codemycom 9 месяцев назад
Glad you enjoy them!
@anushav6304
@anushav6304 3 года назад
Can you please do a video of searching image
@sheddtutt7875
@sheddtutt7875 3 года назад
In your video description u made a typo error. It should be Venue.objects.filter(name__contains=searched) Not name__containts as you wrote
@Codemycom
@Codemycom 3 года назад
Ha thanks
@KAILASHCHANDRA-jq6wf
@KAILASHCHANDRA-jq6wf 3 месяца назад
GOOD ONE MY FRIENDS
@Codemycom
@Codemycom 3 месяца назад
thanks
@ahmadshareef6893
@ahmadshareef6893 Год назад
where is the source code ):
@Codemycom
@Codemycom Год назад
In the pinned comment...just where I say it is in the video :-p
@aminahrasool3564
@aminahrasool3564 3 года назад
Thank you, Sir! Would you please help to query all the records from a specific start date to an end based on the DateTime field? I'm facing an issue. Kindly guide me through!
@Codemycom
@Codemycom 3 года назад
Interesting idea
@fasttracktechnologies
@fasttracktechnologies Год назад
Thank you so much
@Codemycom
@Codemycom Год назад
Welcome!
@eduardsanchez6962
@eduardsanchez6962 3 года назад
when i add the {%url 'show_venue' venue.id%} it gives me errors no Reverse for 'show_venue' with arguments '('',)' not found. 1 pattern(s) tried: ['show_venue/(?P[^/]+)$']
@oe669
@oe669 Год назад
Thank you man!
@Codemycom
@Codemycom Год назад
Welcome!
@Kennerdoll
@Kennerdoll 2 года назад
I guess I was just tired last night, today I have seen all the lines I forget, and thanks bro five stars for you.
@Codemycom
@Codemycom 2 года назад
Glad you got it sorted!
@Alfakhri99
@Alfakhri99 2 года назад
Thanks a lot, I'm coming from your playlist Create a simple Django blog to add search bar feature. This video helped me a lot to implement it. your style is very easy to follow and less coding Thanks again.
@Codemycom
@Codemycom 2 года назад
Glad to hear you're enjoying the videos!
@tamiltechguyz7264
@tamiltechguyz7264 3 года назад
Sir I am following all your videos but request to share ne the roles and permission access to templates in decoratorsq
@Codemycom
@Codemycom 3 года назад
No idea what you're talking about. There are no such things to share
@lashachan
@lashachan 3 года назад
Great tutorial as always. Can you do a multiple-column search Tutorial? Such as Excel filter when you can search for several columns.
@Codemycom
@Codemycom 3 года назад
Not a bad idea
@lonjezano
@lonjezano 3 года назад
Hey, thanks for this straightforward video but I want to paginate the search results. Since we checking for searched in the if, the else get executed when you try to go to the next page. So my question is how can we paginate the search results without running into errors or triggering the else statement
@Codemycom
@Codemycom 3 года назад
Good question, I'll have to do a video on it
@technoiris9868
@technoiris9868 3 года назад
Thank you so much...I had been searching for such a straight forward tutorial...I'm glad I found one..🤗thanks a bunch..
@Codemycom
@Codemycom 3 года назад
Glad you liked it!
@bidlby
@bidlby 2 года назад
you are amazing for sure i'll buy the full package :)
@Codemycom
@Codemycom 2 года назад
Awesome
@cyq3255
@cyq3255 3 года назад
Thanks for this video I was't sure where to start to add a search function for my django project and with your video I can now just adapt it to suit my needs. Very helpfull thanks.
@Codemycom
@Codemycom 3 года назад
Glad it helped!
@didiernzimbi2996
@didiernzimbi2996 2 года назад
So many thanks... it's really amazing how easy you make it look like. Thank you :)
@Codemycom
@Codemycom 2 года назад
Happy to help!
@ahgpy
@ahgpy 3 года назад
the next playlist about this is discord.py bot maker so can u do it pls
@Codemycom
@Codemycom 3 года назад
No, sorry
@F3ND1MUS
@F3ND1MUS 3 года назад
Ty
@Codemycom
@Codemycom 3 года назад
Welcome!
@codeKeshav
@codeKeshav 3 года назад
Sir John, what is your perception about *WhiteHatJr*
@Codemycom
@Codemycom 3 года назад
I don't know what that is
@codeKeshav
@codeKeshav 3 года назад
@@Codemycom Ok Leave that... API connected Currency Convertor # Connected with an API that provides latest currencies value. def getcurrentlist(): import os os.system('pip install openexchangerate') from openexchangerate import OpenExchangeRates client=OpenExchangeRates(api_key='522e7989e9f64eb1ba21a035674dc275') global A,j k=client.currencies()[0] j=client.latest()[0] try: k.pop('VEF') # VEF has got Old except: pass A=[] for i in k: A.append([k[i],j[i]]) A.sort() getcurrentlist() from tkinter import * from tkinter.ttk import Combobox root=Tk() root.title('Currency Convertor') ComboboxList_Name=[] for i in A: ComboboxList_Name.append(i[0]) def load(e): if currency_Entry.get()=='': currency_Entry.insert(0,'0') x_name=Currency_combobox_1.get() for i in A: if i[0]==x_name: x_value=float(i[1]) break y_name=Currency_combobox_2.get() for i in A: if i[0]==y_name: y_value=float(i[1]) break feeded_value=float(currency_Entry.get()) calc_value=f'{round((y_value*feeded_value)/(x_value),2)}' display.config(text=f'{feeded_value} {x_name} equals {calc_value} {y_name}') Currency_combobox_1=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name) Currency_combobox_1.pack() Currency_combobox_1.set('Indian Rupee') Currency_combobox_1.bind('', load) currency_Entry=Entry(root, font=('Agency FB','30','bold'), borderwidth=0, bg='lightblue') currency_Entry.pack() currency_Entry.insert(0,round(j['INR'],2)) currency_Entry.bind('', load) To_label=Label(root, text='To', font=('Agency FB','30','bold')) To_label.pack() Currency_combobox_2=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name) Currency_combobox_2.pack() Currency_combobox_2.set('United States Dollar') Currency_combobox_2.bind('', load) display=Label(root, text=f'Rs. {round(j["INR"],2)} Indian Rupee equals ${j["USD"]} United States Dollar.', font=('Agency FB','30','bold')) display.pack(pady=30) root.mainloop()
@ginalenetti5040
@ginalenetti5040 2 года назад
Hi, is this code available to look at?
@Codemycom
@Codemycom 2 года назад
Of course, it's always linked in the pinned comment.
@saivarshan8288
@saivarshan8288 3 года назад
If we search vegan(wrong spelling) instead of vegas. Will it return results? If not how to do it.
@Codemycom
@Codemycom 3 года назад
try it and see...why would it return results for a thing that doesn't exist? If I search pancakes, it won't return anything either :-p But, we wouldn't want it to, right?
@saivarshan8288
@saivarshan8288 3 года назад
@@Codemycom I am asking this commonly and not in this proj specifically. I am asking If the user mistypes will it return results related to the search
@saivarshan8288
@saivarshan8288 3 года назад
@@Codemycom I don't think it will. But how to do it. I created a proj where user can asks question and others can answer (like stackoverflow) and others can answer for it. If another user searches searches with related keywords in the question how to return results with related words searched by the user I know this is out of the scope of the project. But please help me out
@thetj7093
@thetj7093 3 года назад
@@saivarshan8288 really late and you've prbbly got it sorted out already but in case you have't, an immediate solution I can think of is training a searcher with some datasets so it can recognize mistyped words - such as vegan/vegaa/vegad/vegss for vegas, but this can get really complex if you've never used ML (an immediate DS I can think of is a decision tree) before. Then there's the dummy solution of including a list of mistyped versions for each keyword that the user can search by. Given how seemingly common this is, there should be exisiting algos/models that perform similarly, so you can give that a try too
@chintanbrinda
@chintanbrinda 3 года назад
How can I search by address as well?
@Codemycom
@Codemycom 3 года назад
just filter by address instead of name in the query.
@meirlanbekturganov7874
@meirlanbekturganov7874 2 года назад
BEST TUTORIAL JESUS!!!!!
@Codemycom
@Codemycom 2 года назад
Ha thanks
@snehlatasharma2411
@snehlatasharma2411 3 года назад
i got case error while searching.
@Codemycom
@Codemycom 3 года назад
how is that possible? :-p
@darshantank554
@darshantank554 3 года назад
How to create one search bar for multiple fields. Like you can search users as well as Venues from one searchbar ?
@Codemycom
@Codemycom 3 года назад
Same way, just add another line like this to the views.py function: second_search= Venue.objects.filter(name__contains=searched) change Venue to whatever other model you want to search...then pass that variable to the context dictionary
@darshantank554
@darshantank554 3 года назад
@@Codemycom Good idea but, Don't you think it sounds like a temporary solution !?
@Codemycom
@Codemycom 3 года назад
@@darshantank554 In no way whatsoever is that a temporary solution.
@hiwab41
@hiwab41 3 года назад
Nice video!
@Codemycom
@Codemycom 3 года назад
Thanks!
@rajasaraf6602
@rajasaraf6602 3 года назад
breaking bad
@Codemycom
@Codemycom 3 года назад
ha
@learnnow9598
@learnnow9598 3 года назад
Next for flask💙🤩
@Codemycom
@Codemycom 3 года назад
Flask fridays are awesome :-)
@seforaabigail6704
@seforaabigail6704 2 года назад
Thank u!!💗
@Codemycom
@Codemycom 2 года назад
welcome
@hamdyramzy4350
@hamdyramzy4350 3 года назад
u are the best ♥
@Codemycom
@Codemycom 3 года назад
thanks!
@smartlearning4857
@smartlearning4857 3 года назад
Excellent Sir
@Codemycom
@Codemycom 3 года назад
Thanks
@angelozanonaneto2228
@angelozanonaneto2228 2 года назад
Awesome!!
@Codemycom
@Codemycom 2 года назад
Thanks!
@aguspe532
@aguspe532 3 года назад
Great video!
@Codemycom
@Codemycom 3 года назад
Thanks!
@iihhtt
@iihhtt 3 года назад
Great tutorial
@Codemycom
@Codemycom 3 года назад
Thanks!
@Gemmmvoterpalautot1234
@Gemmmvoterpalautot1234 3 года назад
Thanks, John. ♥️
@Codemycom
@Codemycom 3 года назад
Thanks for watching!
Далее
Update and Edit Venues - Django Wednesdays #10
16:09
Просмотров 37 тыс.
11 ming dollarlik uzum
00:43
Просмотров 1,4 млн
Being Competent With Coding Is More Fun
11:13
Просмотров 84 тыс.
Most Beginner React Developers Do This Wrong
13:47
Просмотров 233 тыс.
Please stop using px for font-size.
15:18
Просмотров 172 тыс.
create a basic search in django
7:48
Просмотров 11 тыс.
Search Functionality in Django Project
30:03
Просмотров 30 тыс.
Django Search
1:31:18
Просмотров 20 тыс.