I had to redo everything beacuse I messed up the whole exercise last time. well. Repetition is also a good teacher ( I hope .)
The first code in exercise 50 worked fine as last time.
It was when I added the template/index.html to the code I run into a problem I could not see why it occurs. It didnt happened to me last time.
I got this error:
status < 200 or status in (204, 304)):
TypeError: '<' not supported between instances of 'str' and 'int'
THello.
Thanks for reply.
My guess was that âstatus_num = int(status)â was supposed to be in test/test_app.py.
But it didnt help. Except for I had to change âimport flaskâ to âfrom flask import Flaskâ my Pytest file works perfekt whitout it (Github updated).
It is when I start the app (python app.py) and refresh the window(browser) I get this error in terminal:
Error on request:
Traceback (most recent call last):
File "/home/ulf/Documents/python/LPTHW/projects/ex51/flask-venv/lib/python3.6/site-packages/werkzeug/serving.py", line 269, in run_wsgi
execute(self.server.app)
File "/home/ulf/Documents/python/LPTHW/projects/ex51/flask-venv/lib/python3.6/site-packages/werkzeug/serving.py", line 260, in execute
write(data)
File "/home/ulf/Documents/python/LPTHW/projects/ex51/flask-venv/lib/python3.6/site-packages/werkzeug/serving.py", line 231, in write
status < 200 or status in (204, 304)):
TypeError: '<' not supported between instances of 'str' and 'int'
Where was the int(status) supposed to be?
I was thinking I put in a " < " somewhere it shouldânt be.
Ok, I had to reformat you error message and now I see that this doesnât seem to be coming from you really but from deep inside Flask. So youâre saying if you change this line:
To use import flask then you get this error in your Pytest, but if you set it to from flask import Flask then you donât get the error.
Iâd say then thatâs your fix, and this is mosts likely a bug in flask or how youâre running it. Are you doing flask run to run it?
It is not with Pytest I have problem in this exercise. At least not yet.
Its with app.py or index.html there are something I did wrong this time.
Mostly I run it with âpython app.pyâ
I always do this with venv activated. Then I got python -version 3.6.3.
I tried the âflask runâ the first time tonight. I got another Error message then:
[File "/home/ulf/Documents/python/LPTHW/projects/ex51/flask-venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ulf/Documents/python/LPTHW/projects/ex51/app/app.py", line 9, in index
return render_templates("index.html", greeting=greeting)
NameError: name 'render_templates' is not defined
File "/home/ulf/Documents/python/LPTHW/projects/ex51/flask-venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ulf/Documents/python/LPTHW/projects/ex51/app/app.py", line 9, in index
return render_templates("index.html", greeting=greeting)
NameError: name 'render_templates' is not defined
I found an error in here. ârender_templatesâ . A letter too much(âsâ).
But correcting this gave me just another error message in the browser:
The connection was reset
The connection to the server was reset while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computerâs network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
I guess I did something wrong this time. It did not happened the first time. But I just cannot see it my self.
perhaps I have to do something else for some days?
This is just a hobby for me. Fortunately I do not have any deadline to follow. Just learn it to make interesting projects.
Ok thatâs actually better. Now you need to start trying to debug this rather than assuming something is wrong with your setup. Remember every time you get a NameError itâs only:
You spelled something wrong.
You didnât define or import something you needed.
In this case, you spelled render_templates but itâs render_template. As you get further errors, look for solutions. Look at every line and also make sure to compare every line that I have to what you have.
Thanks for helping me again.
I followed your checklist (and added a little bit more).
It was not any bad spelling anywhere.
I had the required imports for what I was working with.
So I tried a little bit more
And Google a lot.
I got a new error. âTemplateNotFoundâ
There are some ways to âdirectâ to templates folder.
I have not tried them yet.
I found another flask project I have that worked fine.
The âapp.pyâ file was in the same folder as templates folder.
projects/
ex 51/
app.py (works fine in here)
app/ (app.py does NOT work in here)
docs/
bin/
tests/
templates/ index.html
I see that you do have a spelling mistake though. You use render_templates but it should be render_template (singular). I believe you might have fixed that, but check it. Next, try doing this:
export PYTHONPATH=.
If youâre on Windows let me know as itâs different. That should force it to use the local directory. Next, you should watch the video. I do this whole setup and if you follow my steps you should be able to figure it out from how I did it.
Yes. The spelling is corrected.
So is also the directory structure to be like the one you described in ex50.
I think the mistakes I did was that the app.py and templates folder was not in the same directory. When I found out it worked again.
My âTreeâ looks like this now: