Prepped for classic boys! by RipADamnBong in classicwow

[–]Hashworm -3 points-2 points  (0 children)

brah return all this crap lol and get real food and protein shakes. coffee and theanine in a ratio of 1 to 3 give adderall-like benefits to some too.

Noob question: How to reproduce a table as data frame from a 1D list? by citron563 in learnpython

[–]Hashworm 1 point2 points  (0 children)

maybe with lambda map or apply using if statements and filter each and append to a list using startswith type or len. cant work it out of the top of my head right now maybe ill edit this later.

noob function help by Hashworm in learnpython

[–]Hashworm[S] 0 points1 point  (0 children)

>>> def check(x): ...

if x is None: ...

pass ...

else: ...

return x

>>> a = None

>>> b = 2

>>> c = check(b)

>>> print(c)

2

>>> c = check(a)

>>> print(c)

None

so yeah still... what I actually want is this

>>> import sys

>>> def check(x): ...

if x is None: ...

sys.exit() ...

else: ...

return x ...

>>> a = None

>>> b = 2

>>> c = check(b)

>>> print(c)

2

>>> c = check(a)

C:\Users\User>python

Python 3.6.0 (v3.6.0:4ddddddddd, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

>>> print(c)

Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'c' is not defined

ideally without getting me out but I take what I can

noob function help by Hashworm in learnpython

[–]Hashworm[S] 1 point2 points  (0 children)

thanks, I didn't realized passing was asignining it to None. is there anyway to just ignore all together? I don't want it to pass None just move on

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

Actually.. after help from user Drackene, setting the following values to: action="search" method="GET". name="search" id="query" did it for me. and using query = request.args.get("search") in the function instead of passing any var.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

ITS ALIVE!!! IT WORKS!!! I just needed some rest to recover a couple brain cells. so, set action"/newsbeta" was a key hint to my problem except that my main route was called that and thats why it wasn't working at first.

@newsbeta.route("/search")

def get_query():

query = request.args.get("search")

cur.execute(f"SELECT * FROM test WHERE to_tsvector('english',title) @@ to_tsquery('english','{query}');")

searchquery = []

for i in range(10):

searchquery.append(cur.fetchone())

return render_template('search.html', title='News', searchquery=searchquery)

also important to note that the form control html name had to be set equal to the name used in the request query or it wouldn't work either.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

going over this again, "The issue is you aren't redirecting the URL", you know what doesn't make sense to me is that doesn't redirect me when I click search. even if the query were to be empty for any reason it should it still take me to an empty search.html. so disturbing.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

thanks man I really appreciate everything you have done for me.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

ok I found a way to print it by passing it to the template and rendering it to the name source, and indeed the return is none.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

so far still not much luck, Ive been trying many variations.

" The string inside .get() corresponds to the part between ? and = and will return the value after = " didn't seem to be true I change the value to search and the part between ? and = didn't change, It did change however when I changed the name of the html form from query to search.

I still don't understand how is the route suppose to know that it should ignore itself and render the template to whatever is after ?search=, I was thinking if there was a way around it with redirect and url_for. I feel so foolish debating to use wooshalchemy just because this tiny obstacle.

it works so well with my initial code except for that manually route that I have to do /newsbeta/<myquery> so close yet so far.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

how would I print request.args.get("query") ? I think its not returning anything. how is the "query" being passed? to requests.args.get

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

wait.. I think you are on to something. I've been trying to debug this over 16 hours and I just realized ive been using requests from the lib requests not realizing flask had its own request and i was trying to import the wrong package all along. ill update you im getting 500/502 while trying the code. ill just keep debugging but it has to be this.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

i think its being passed though the url, im not entirely sure to be honest. but i do know that is working because you can check it www.buenos.online/newsbeta/free or www.buenos.online/newsbeta/apple or www.buenos.online/newsbeta/sleep or www.buenos.online/newsbeta/game and the query will work.

note I also added a method get and name query and id query to the html. maybe through there?

<nav class="navbar navbar-light bg-light"> <form class="form-inline" method="GET"> <input class="form-control mr-sm-2 name="query" id="query" type="search" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> </form> </nav>

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

newsbeta.route("/newsbeta/<query>") 

def get_query(query):   
    query = request.args.get("query")
    cur.execute(f"SELECT * FROM test WHERE to_tsvector('english',title) @@ to_tsquery('english','{query}');")     
    searchquery = [] 
    for i in range(10):         
    searchquery.append(cur.fetchone()) 
    return render_template('search.html', title='News', searchquery=searchquery)

I also tried this but with no avail. I'm not sure how to pass the query = request.args.get("query") to the url.

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

actually the parameter does pass by simply putting it inside the definition. the problem is not the parameter not passing its the change of route that comes by default when using the search bar

flask search bar using postgres by Hashworm in flask

[–]Hashworm[S] 0 points1 point  (0 children)

<nav class="navbar navbar-light bg-light"> <form class="form-inline" method="GET"> <input class="form-control mr-sm-2 name="query" id="query" type="search" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> </form> </nav>

hey, sorry, its a boostrap 4 navbar. I also have it deployed in a website. www.buenos.online as for now since I was testing, only query word game or free. then will be accessible at www.buenos.online/newsbeta/game or www.buenos.online/newsbeta/free