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

yes but i can't worry about that now. It's too much to incorporate with already having problems with the python/sql syntax.


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

Is this actually for a school project? You mention having time constraints here (14 days or so at the time of writing) and your tracebacks in other threads show your files are under a directory called "school" (e.g. here). OK, I may be making a big leap with the second. If you are doing this for school, though, I really think its in your best interests to talk to your teachers, since you're struggling quite a lot.


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

I'm doing this on my own with a free course online. There are really no teachers who can help - just forums - which i do post in but haven't been getting responses lately.

There is no time limit but on July 1st they are switching this project to another so I won't get submission credit.

I still have a few steps to complete. I probably won't finish but I'm going to try. Been working on it for about 2 months.


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

What's the course, out of interest?

Do you have updated code now?


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

OK I'm looking at the page you sent me and it just doesn't explain anything. Here are my questions:

Rendering Templates:

from flask import render_template

@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
    return render_template('hello.html', name=name)
It shows that as an example. The first line I understand (only because I've used it before - it doesn't explain what it does) the second line I assume is just the URL with the name inserted to another level of the directory. Why? It doesn't say what the advantage is of this. The third line what is name=None and why is it set to None? What is "name" even coming from? I scrolled all through the page and there's not a single reference to "name" anywhere else. Then, finally, the final line makes no sense to me whatsoever. name=name? Where is name coming from? Why are we naming it anything? Where is the user input of name?

I literally have questions like this for the entire page. It's not helpful at all to me. Am I missing something? I've read the whole page like 3 times now.

(Jun-17-2020, 06:43 AM)ndc85430 Wrote: What's the course, out of interest?

Do you have updated code now?

No I'm still looking and the code and don't even know where to start.

It's the web development course on EDX.

<!doctype html>
<title>Hello from Flask</title>
{% if name %}
  <h1>Hello {{ name }}!</h1>
{% else %}
  <h1>Hello, World!</h1>
{% endif %}
Here's the next block of code. I get what it's doing - it's simple. But where is name coming from? how is this a working example of anything?

It really doesn't apply to my project.

Where's the instructions of the syntax?


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

(Jun-17-2020, 06:44 AM)card51shor Wrote: OK I'm looking at the page you sent me and it just doesn't explain anything. Here are my questions:

Rendering Templates:

from flask import render_template

@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
    return render_template('hello.html', name=name)
It shows that as an example. The first line I understand (only because I've used it before - it doesn't explain what it does) the second line I assume is just the URL with the name inserted to another level of the directory. Why? It doesn't say what the advantage is of this. The third line what is name=None and why is it set to None? What is "name" even coming from? I scrolled all through the page and there's not a single reference to "name" anywhere else. Then, finally, the final line makes no sense to me whatsoever. name=name? Where is name coming from? Why are we naming it anything? Where is the user input of name?

I did say above that some of the example is a bit different to yours and was implying that you shouldn't spend too much time focusing on all the details. In any case, most of your questions are answered elsewhere in the docs, particularly the section on routing. The call to render_template is key. Firstly, do you know what keyword arguments are? The paragraph immediately above that code sample tells you what you need to know. name is clearly a parameter to the function (line 5), or are you saying you don't understand how functions work either? Again, how the value is set for that parameter is answered in the section on routing.

Quote:
(Jun-17-2020, 06:43 AM)ndc85430 Wrote: Do you have updated code now?

No I'm still looking and the code and don't even know where to start.

I'm confused. Earlier, you said you tried something and then deleted it because it wasn't working. You'd said you were going to try again, so I expected to see that code. We're just going round in circles here.


Quote:
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
  <h1>Hello {{ name }}!</h1>
{% else %}
  <h1>Hello, World!</h1>
{% endif %}
Here's the next block of code. I get what it's doing - it's simple. But where is name coming from? how is this a working example of anything?

The two pieces of code together are the working example. The paragraph before the first code example is the important one. What didn't you understand from it? I suggested very early on to try the example, but you didn't even bother to do that. If it helps, just remove the function parameter and the variable route and hard code a value for the namevariable.

Quote:It really doesn't apply to my project.

Why do you think that?

Quote:Where's the instructions of the syntax?

We've been through that already: https://jinja.palletsprojects.com/en/2.11.x/templates/. This link is literally in a sentence just before the template.


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

Yes I know what keyword arguments are and what parameters to a function are. Why is it using this line @app.route('/hello/<name>')? def hello(name=None): Why is name being declared as none as a parameter? So that it just says "Hello World"?

I just don't see where name is in the paragraph above my first example, which is this :

from flask import request

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        return do_the_login()
    else:
        return show_the_login_form()
Where is "name" referenced?



I was experimenting with code last night - i was just getting errors and being frustrated so I just reset to my working code. So now I don't have that. It wasn't anything useful anyways.

I don't think it applies to my project because it isn't getting a user value that is a list and displaying it on the screen. Most importantly - It's not showing me the HTML.



So If I can't understand how to do what I have to do after reading that page 3 times - I should quit? Ask you guys for help? What should I do?

It's really that easy? I'm just totally missing it? All the info I need is right there?

I'm not trying to be snarky, by the way. I honestly want to know - if I still don't get it - am I an idiot? Is it that easy to understand? Most people could read those instructions and know how to start coding what I have to do?


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

(Jun-17-2020, 07:38 AM)card51shor Wrote: Yes I know what keyword arguments are and what parameters to a function are. Why is it using this line @app.route('/hello/<name>')? def hello(name=None): Why is name being declared as none as a parameter? So that it just says "Hello World"?

Did you read the section on routing? Did you try the example? What information did you glean from doing those things?

Quote:I just don't see where name is in the paragraph above my first example, which is this :

from flask import request

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        return do_the_login()
    else:
        return show_the_login_form()

That's in an entirely different section that describes HTTP methods. Your current question is about rendering templates, so I don't know why you'd go to a different section. By paragraph, I meant the text immediately above the code sample.


Quote:I was experimenting with code last night - i was just getting errors and being frustrated so I just reset to my working code. So now I don't have that. It wasn't anything useful anyways.

I've said this before, but we can't help unless we see your attempts.

Quote:I don't think it applies to my project because it isn't getting a user value that is a list and displaying it on the screen. Most importantly - It's not showing me the HTML.

You need to learn to abstract a bit - the important things are that there is variable data coming from somewhere and that data is being shown on a page. In the example, the data comes from the request path (by the way, paths in URLs don't necessarily relate to a directory structure), but for yours it comes from the database. The two cases are the same in the sense that they're about getting stuff rendered in a template. The HTML is shown - that's what the template is.

Quote:So If I can't understand how to do what I have to do after reading that page 3 times - I should quit? Ask you guys for help? What should I do?

It's really that easy? I'm just totally missing it? All the info I need is right there?

I'm not trying to be snarky, by the way. I honestly want to know - if I still don't get it - am I an idiot? Is it that easy to understand? Most people could read those instructions and know how to start coding what I have to do?

I don't know what to suggest here, other than playing with the examples, trying to change them and work stuff out. Perhaps a forum really isn't the best place for you to get help; I don't know.

Are you saying you weren't taught any of these things in the course? I'd expect a course on web development to explain this stuff.


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

It's just a learn it yourself course. You go at your own pace. You keep suggesting I haven't tried to tinker around and do code. I've been doing this for 2 months. I finally figured out how to make it search the database. I kept asking for help with the syntax all the while messing with the code like I do every day - I finally figured it out.

I suggest I'll eventually figure this out - but if I don't in 13 days then all my work for 2 months is down the drain.

I appreciate your help.

Maybe someone else can help me out more hands on and show me what they would do and give me some suggestions.

I'm sorry - I know I keep saying it - but I'm just not getting it from reading other people's code that is doing other things (even slightly) different than I want to do.

So, in my project, "name" would be the id and the name of the search box?

I don't see any section on routing on the page you gave me. if you're talking about @app.route, then yes I've used that before in my code and I used it in my example that I pasted to start this thread. But I haven't used it to pass any variables.

I read Rendering Templates - and I understand that code but it doesn't really help me start my code since I'm doing different things. But yes, I can see how it would work for that situation.


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

(Jun-17-2020, 07:55 AM)card51shor Wrote: It's just a learn it yourself course.

But they must give you materials from which to learn the concepts, no?

Quote:You keep suggesting I haven't tried to tinker around and do code.

Again, you're not showing these attempts so I don't have any idea what they look like.


Quote:So, in my project, "name" would be the id and the name of the search box?


Well, no, you want to use the variable that contains the data you want to render.

Quote:I don't see any section on routing on the page you gave me.

You can't be serious. Look at the contents on the left hand side - it's two sections above "Rendering Templates". Having said that, I think you're getting confused again. That section will help you understand the variable routes if you want, but you don't really need it for your stuff at the moment. I only suggested reading that because it sounded like you wanted to understand completely the template rendering example.