-
-
Notifications
You must be signed in to change notification settings - Fork 953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this.
In StaticFiles html-mode, when
404.html
andindex.html
files were missing, a FileNotFoundError exception was rised. As I understand it, a non-existent file was checked in theos.stat
functionHowever, this is not the whole problem. Even if
404.html
exists, it might not be returned, because after checking for the existence ofindex.html
, a basic 404 exception is returned, rather than returning a404.html
file with the correct status codeTherefore, I moved the check for the existence of a
404.html
to the end, when index cannot be found. I also considered it correct to move the file absence exception to thelookup_path
and, in case of absence, return an empty string and None, so as not to process Exception several times.Sorry for my bad english