Python Forum
Displaying search results - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Displaying search results (/thread-27661.html)

Pages: 1 2 3 4 5 6 7 8 9


RE: Displaying search results - card51shor - Jun-17-2020

oh OK I see Routing now. I do know how to do that. The example is very simple.

The next section, Variable Rules, is too complex and doesn't explain the code clearly. In fact, just looking at it confuses me greatly - especially not knowing what the variables actually correspond to.

Is it using SQL to get info from a database? What's the HTML? Without seeing all that information I just can't do it.

I'm just not good enough to do it without clear laid out instructions to learn.


RE: Displaying search results - ndc85430 - Jun-17-2020

OK, I edited my last post. I think it's confusing you more to look at variable routes now, so perhaps don't. FWIW: the examples are quite straightforwards though - there's no HTML or SQL there. They're just showing you how to do variable paths in your URLs and access those variable bits in your handlers. That's all. Again, please try things out if you want to understand how they work. The text even tells you how the examples work.

I may have to bail out now. We're going round in circles, so that isn't productive. You won't show your attempts to get stuff to work, so there's nothing more I can really do. I'm certainly not going to do the work for you.


RE: Displaying search results - card51shor - Jun-17-2020

OK well thanks for trying to help.

Is there anyone else who can please try to help me out? I'll work with you in any way just please don't give me a link - I'm sorry - I tried - I just don't get it.

Thanks.


RE: Displaying search results - SheeppOSU - Jun-17-2020

Maybe your just trying to interpret the documentation in the wrong way. You should use the documentation not rly to understand how the code example is working, but how the mechanics of various functions are working. @app.route('url/<variableName>') maps the function to the route url/any-string. I can go to url/hello, url/hi, url/hey, etc. It then passes that variable name to the function. If I make it @app.route('user/<username>') then if I were to go to "user/sheepposu" it would pass sheepposu to the function where the function as a parameter -> def account(username). The reason we're not doing username=None like the documentation example is because we don't have app.route('user') as one of the routes. Otherwise we'd need it to have a default value, because if they go to simple "user/" they enter no username and it will give an error I'm pretty sure. In render template it's almost the same concept. You pass and you receive. Pass an argument into render_template and receive the argument inside the HTML file. Then you can use it via the curly braces syntax. Hopefully you understand now. Maybe next time try to focus more on how each individual mechanic of the code works rather than how the whole code example works and trying to apply it to your own code. It's like taking a huge lego and trying to morph it into something else vs a bunch of small legos which can easily be taken apart and rebuilt into something else.


RE: Displaying search results - card51shor - Jun-17-2020

That makes a lot of sense - thanks. Trying to explain things really helps me. I've studied the code for so long and when I try to type my own - I just freeze up.

Not usually - just with Python. The syntax is baffling to me.

But I'll give it a try tonight with your information - that's the first time since I've been on this forum where people actually explained stuff

"OK, I edited my last post. I think it's confusing you more to look at variable routes now, so perhaps don't. FWIW: the examples are quite straightforwards though - there's no HTML or SQL there. They're just showing you how to do variable paths in your URLs and access those variable bits in your handlers. That's all. Again, please try things out if you want to understand how they work. The text even tells you how the examples work."

It's not true. The text does not explain the code. I read it all. It doesn't explain it.


RE: Displaying search results - ndc85430 - Jun-17-2020

(Jun-17-2020, 04:04 PM)card51shor Wrote: It's not true. The text does not explain the code. I read it all. It doesn't explain it.

It really does. The first sentence says

Quote:You can add variable sections to a URL by marking sections with <variable_name>. Your function then receives the <variable_name> as a keyword argument.

and the first handler (shows_user_profile) demonstrates that. If you ran the example and tried different paths (e.g. /user/bob, /user/alice), you'd see it working. For whatever reason, you seem to not even want to do that.


RE: Displaying search results - card51shor - Jun-17-2020

But I understand that example. I don't need to do it. It's very simple and doesn't take user input.

I understand that it was using a variable - but the instructions said nothing about the user having to put their own name in the url for it to work.

But - again - yes - I understand that example.

Do you have an example of what I am trying to do though?

I'm going to try what Sheepp sent me tonight. I have a feeling I'm not going to figure it out though but I'll try.

I'll post my code tonight. Thanks guys.


RE: Displaying search results - ndc85430 - Jun-18-2020

If you understand the example, then you should be able to understand the templating example which shows you how to get a variable into a template to dynamically generate HTML. That's an example of what you're trying to do.


RE: Displaying search results - card51shor - Jun-18-2020

OK I'm figuring it out. Right now I am able to print the information out on the screen using this code:

<ul id="results">
          {% for i in search %}
            <li>{{i}}</li>
          {% endfor %}
      
        </ul>
Only problem is, I need to create a link for each individual item on the list that has it's own page.

I know I can copy the template you showed with the username as the url...however, I'm having trouble with the syntax of the <a href="">. I have to put {{i}} as the url but I'm getting all sorts of errors.

I tried <a href="{{i[0]}}"></a>. I tried without the quotes, etc.

What is the best way to go about this? Thanks guys.


RE: Displaying search results - ndc85430 - Jun-18-2020

Show us the code you're trying in full and what the errors are. Again, we can't see your screen and making is guess is unhelpful.