Python Forum
Displaying search results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying search results
#46
(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.
Reply


Messages In This Thread
Displaying search results - by card51shor - Jun-16-2020, 05:37 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 06:04 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:06 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 06:14 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:19 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 06:20 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:23 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 06:24 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:26 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 06:29 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:36 AM
RE: Displaying search results - by buran - Jun-16-2020, 06:49 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 06:54 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 07:11 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 07:20 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 07:28 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 07:34 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 07:44 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 07:58 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 08:34 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 03:29 PM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 08:01 PM
RE: Displaying search results - by card51shor - Jun-16-2020, 08:36 PM
RE: Displaying search results - by card51shor - Jun-17-2020, 12:41 AM
RE: Displaying search results - by SheeppOSU - Jun-16-2020, 07:40 AM
RE: Displaying search results - by card51shor - Jun-16-2020, 07:51 AM
RE: Displaying search results - by ndc85430 - Jun-16-2020, 07:56 AM
RE: Displaying search results - by buran - Jun-16-2020, 07:50 AM
RE: Displaying search results - by buran - Jun-16-2020, 07:56 AM
RE: Displaying search results - by SheeppOSU - Jun-16-2020, 08:37 AM
RE: Displaying search results - by pyzyx3qwerty - Jun-16-2020, 04:26 PM
RE: Displaying search results - by pyzyx3qwerty - Jun-17-2020, 02:01 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 02:41 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 04:35 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 05:18 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 05:29 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 05:41 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 05:42 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 05:51 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 06:18 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 06:32 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 06:33 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 06:35 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 06:43 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 06:44 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 07:28 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 07:38 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 07:49 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 07:55 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 08:06 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 08:12 AM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 08:15 AM
RE: Displaying search results - by card51shor - Jun-17-2020, 08:18 AM
RE: Displaying search results - by SheeppOSU - Jun-17-2020, 03:22 PM
RE: Displaying search results - by card51shor - Jun-17-2020, 04:04 PM
RE: Displaying search results - by ndc85430 - Jun-17-2020, 05:29 PM
RE: Displaying search results - by card51shor - Jun-17-2020, 05:44 PM
RE: Displaying search results - by ndc85430 - Jun-18-2020, 04:23 AM
RE: Displaying search results - by card51shor - Jun-18-2020, 04:54 AM
RE: Displaying search results - by ndc85430 - Jun-18-2020, 05:01 AM
RE: Displaying search results - by card51shor - Jun-18-2020, 05:33 AM
RE: Displaying search results - by ndc85430 - Jun-18-2020, 05:43 AM
RE: Displaying search results - by card51shor - Jun-18-2020, 05:52 AM
RE: Displaying search results - by ndc85430 - Jun-18-2020, 05:56 AM
RE: Displaying search results - by card51shor - Jun-18-2020, 05:58 AM
RE: Displaying search results - by ndc85430 - Jun-18-2020, 05:59 AM
RE: Displaying search results - by card51shor - Jun-18-2020, 06:35 AM
RE: Displaying search results - by ndc85430 - Jun-19-2020, 05:40 AM
RE: Displaying search results - by card51shor - Jun-19-2020, 07:01 AM
RE: Displaying search results - by card51shor - Jun-19-2020, 09:59 PM
RE: Displaying search results - by ndc85430 - Jun-20-2020, 05:47 AM
RE: Displaying search results - by card51shor - Jun-20-2020, 07:43 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 12:38 AM
RE: Displaying search results - by ndc85430 - Jun-21-2020, 05:06 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 05:25 AM
RE: Displaying search results - by ndc85430 - Jun-21-2020, 05:44 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 05:45 AM
RE: Displaying search results - by ndc85430 - Jun-21-2020, 05:47 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 05:48 AM
RE: Displaying search results - by ndc85430 - Jun-21-2020, 05:56 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 06:00 AM
RE: Displaying search results - by ndc85430 - Jun-21-2020, 06:00 AM
RE: Displaying search results - by card51shor - Jun-21-2020, 06:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020