Fix Staticfiles 404.html in HTML mode#1314
Conversation
404.html and index.html doesn't exist404.html and index.html doesn't exist
|
I looked at the history of file changes. At 1db8b5b (#1220) has undergone "devastating" changes. For some reason, check of the Obviously, we must first check |
aminalaee
left a comment
There was a problem hiding this comment.
I think that was moved by mistake.
Maybe you can add tests for it so this won't happen again?
|
Hmmm... @aminalaee, I don't understand the testing system well, but I have a problem Tests fail due to HTTPException being called: I've seen this same construct in other tests. And no exception is raised there. I need help with this. Even while writing the tests, I noticed that now when 404.html or index.html is not found, the '/' at the end of the URL is removed. |
|
If I understand correctly, you need to write a test to catch an exception? with pytest.raises(RuntimeError) as exc_info:
client.get("/example.txt")This ensures calling the GET will raise the specified exception. As for the removal of the tests, I'd rather we don't change them, that would lead to un-intented changes. |
response = client.get("/dir/")
assert response.url == "http://testserver/dir/"
response = client.get("/dir")
assert response.url == "http://testserver/dir/"Oh, I'm sorry. I made a typo during preliminary testing. Corrected. In some cases a '/' should appear and in others it should not. I got the opposite results due to a typo, but now everything is fine ✨ |
|
I think that's all. I don't plan to make any more changes |
404.html and index.html doesn't exist404.html and index.html don't exist
404.html and index.html don't exist404.html in HTML mode
In StaticFiles html-mode, when
404.htmlandindex.htmlfiles were missing, a FileNotFoundError exception was rised. As I understand it, a non-existent file was checked in theos.statfunctionHowever, this is not the whole problem. Even if
404.htmlexists, it might not be returned, because after checking for the existence ofindex.html, a basic 404 exception is returned, rather than returning a404.htmlfile with the correct status codeTherefore, I moved the check for the existence of a
404.htmlto the end, when index cannot be found. I also considered it correct to move the file absence exception to thelookup_pathand, in case of absence, return an empty string and None, so as not to process Exception several times.Sorry for my bad english