Any one is familiar with flask?


#1

I am learning flask framework .For rendring simple html page i have write code in two saperate file.One is hello.py which is main file and consist of main code .Other one is hello.html.When i try to run flask app on command line it is showing me Serving Flask app "hello"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
But when i tries to open it in browser it is displaying "HelloWorld".Then i tries to open with http://localhost:5000/result .It shows me -->
"The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."I am really very sick of it despite of trying so many times i cannot run it .Although simple hello world app is working .
Here the code lies

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/result')
def result():
   dict = {'phy':50,'che':60,'maths':70}
   return render_template('result.html', result = dict)

if __name__ == '__main__':
   app.run(debug = True)

hello.html code:

<!doctype html>
<html>
   <body>
   
      <table border = 1>
         {% for key, value in result.iteritems() %}
         
            <tr>
               <th> {{ key }} </th>
               <td> {{ value }} </td>
            </tr>
            
         {% endfor %}
      </table>
      
   </body>
</html>

Please try to help me . and assume indenataion as it is there in my code .


#2

Mark the terminal output and python code as preformatted, not just the template :confused:


#3

Sorry .I did not get you .Can you please deescribe it .


#4

If you look at your post - it isn't possible to copy what you posted and run it because the formatting has made the code invalid.

If you fix the formatting, people can copy the code and run it themselves so that they can make their own observations and try things.


#5

file:///home/areeb/Desktop/Screen%20shot/Screenshot%20from%202017-04-03%2001-16-12.png

This is the same code i am using .


#6

Can't copy text from screenshots though >.>


#7

Sorry .I hope this will not irritate you .
https://www.tutorialspoint.com/flask/flask_templates.htm
Just see the code at the bottom of the page .


#8

You said you named the template hello.html, but you're rendering result.html

(in other words, you're running code that is different from the one you shared in the link)

It's really important that you share exactly the same thing as you're running yourself, otherwise you're relying on others compensating by either knowing far more than they would otherwise need to or by putting in a bunch of extra work - similarly, it's just as important when looking for bugs yourself that you're looking at the right things


#9

ok i understand that .But i am trying to put my original code but indentation is not coming there .
I have change that hello.html to result.html but there is no change .


#10

Also, your code doesn't result in 404 on localhost:5000/result - the page is there but the template isn't found because of using different name for the file


#11

I have change file name but nothing happens


#12

If you look at your post, the template is entirely intact. So you could look at how that was done, and do the same with the rest of the code.

Also, it's about the realisation that it needs to be exactly right. So if one way doesn't work one would have to find another way around it. And there are plenty of ways around it, but since it's fairly simple to fix it in the post, that's the best option.


#13

I no longer know what you're running.


#14

I am rendring file result.html and i have created file hello.html therefore i have change hello.html to result.html .


#15

Odds are I'm going to make those changes differently from you.
Show me how to reproduce how you have currently. It needs to be foolproof on both your end and mine, we need to do the same thing.


#16

Ok .What can i do now .


#17

Ok .What can i do now .How i shall proceed .


#18

If there's a problem, you can describe it and show how to reproduce it. But you already know that :confused:
And others will need to see exactly what you're using, so it'll need to be exactly the same.


#19

file:///home/areeb/Desktop/Screen%20shot/Screenshot%20from%202017-04-03%2001-43-43.png.
After making that change i am basically exporting flask app and running it on my command shell .
I hope this is you want or i misunderstood you .


#20

See the problem? I don't get the same outcome. Because we're running different things. You need to share your files.