#9847 closed New feature (fixed)
Improved handling for HTTP 403 Errors
| Reported by: | Nicola | Owned by: | Chris Beaven |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | sprintSep2010 |
| Cc: | paulc@…, jwilk@…, ryan.niemeyer@…, luke crouch, sfllaw@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
in core/handlers/base.py is hardcoded an h1:
<h1>Permission denied</h1>
so this string not transable,
regards
drakkan
Attachments (5)
Change History (38)
comment:1 by , 17 years ago
| milestone: | → 1.1 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 17 years ago
comment:3 by , 17 years ago
| Has patch: | set |
|---|
comment:4 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:5 by , 17 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
Reopening - the fix was a bad idea; see [10347].
comment:6 by , 17 years ago
| Has patch: | unset |
|---|---|
| Owner: | removed |
| Status: | reopened → new |
comment:7 by , 17 years ago
| milestone: | 1.1 → 1.2 |
|---|
comment:8 by , 16 years ago
| Has patch: | set |
|---|
There is no need to have a message at all. 'Permission Denied' is presumed with the 403 HttpResponseForbidden error. If a message must be delivered, it should be added to django/http/init.py for all HttpResponseForbidden errors.
comment:9 by , 16 years ago
I think there should be content in the response, since otherwise you'd show a completely blank page to an end user, requiring them to know about HTTP status codes and how to find out what status code we sent back.
I can see a couple options for doing this:
- Don't bother trying to translate the response content, and just use the language in the HTTP spec (so just "403 Forbidden").
- Set a default
contentvalue forHttpResponseForbidden, and mark it for translation. I think we can do that safely since it's over indjango.httpand settings will already be set up by the time it gets imported.
comment:10 by , 16 years ago
| milestone: | 1.2 → 1.3 |
|---|
Also, this is a minor enough issue that it really ought to happen on 1.3 or a 1.2.X bugfix release.
comment:11 by , 16 years ago
| Patch needs improvement: | set |
|---|
I take back what I said about not having a message at all.
- It shouldn't be hardcoded in base.py, maybe it should be in source:django/trunk/django/http/__init__.py ?
- All the non-200 HTTP errors should derive from a master error class. Right now it's kind of a hodge-podge it seems.
I agree that milestone:1.3 is best.
comment:12 by , 15 years ago
Why not create an exception subclass which would be raised in base.py and caught by a middleware to display a custom 403 page, like with Http404 ?
comment:13 by , 15 years ago
OK, I see middleware is not involved in this process, but it's possible to add a method to the resolver, resolver.resolve403() just like resolve404 and resolve500 which could render 403.html template and if that fails just return 'Permission Denied'
by , 15 years ago
| Attachment: | base.3.diff added |
|---|
comment:14 by , 15 years ago
So here's the patch, I think that this way it would be more flexible so that you can customize the content of 403 as much as you wish. Besides it makes exception handling more consistent, you just create 403.html in the root of your templates dir just like for 404 and 500. What do you think?
comment:15 by , 15 years ago
| Patch needs improvement: | unset |
|---|
comment:16 by , 15 years ago
| Cc: | added |
|---|
comment:17 by , 15 years ago
| Summary: | hardcoded string in core/handlers/base.py → Improved handling for HTTP 403 Errors |
|---|
comment:18 by , 15 years ago
| Cc: | added |
|---|
comment:19 by , 15 years ago
| Keywords: | sprintSep2010 added |
|---|---|
| Needs documentation: | set |
| Needs tests: | set |
| Owner: | set to |
| Status: | new → assigned |
I'm going to try and get this ready for checkin today at the djangocon sprint.
comment:20 by , 15 years ago
| Cc: | added |
|---|
by , 15 years ago
Added tests and docs... anyone care to test my tests?
comment:21 by , 15 years ago
| Needs documentation: | unset |
|---|---|
| Needs tests: | unset |
| Version: | 1.0 → SVN |
comment:22 by , 15 years ago
| Triage Stage: | Accepted → Design decision needed |
|---|
Need some more feedback on this one, so we're going to hold off... in any case, the tests will be useful even if we do something other than a bunch of resolve4xx stuff. Slippery slope... we don't really want 17 different resolve401, resolve402 etc.
comment:23 by , 15 years ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Design decision needed → Accepted |
Tests and docs are fine. As noted, I'd like a way to avoid requiring the module-level resolver403 function. Those functions are really annoying (they require import * from the default url stuff to be used, for example).
comment:24 by , 15 years ago
Just for the record, after [13590] the handlerXXX functions don't require an "import *". This still calls for a more general solution then just putting another function. Also, the current patch required a "403.html" template, but doesn't provide it. This gets catch by "except:"``, but that's at least bad style to me. If I make a syntax error in the ``"403.html" I would expect a 500 and a trace, so that my tests fail when checking the returned status code.
comment:27 by , 15 years ago
| Cc: | added |
|---|
comment:28 by , 15 years ago
It can't go in 1.3.X, as we don't backport features. It could get into 1.4. It currently has 'Patch needs improvement' for some reason. If that is resolved, and it can promoted to 'Ready for checkin', it stands a good chance for 1.4. The way to get things included is to follow our contributing howto to make sure the ticket moves along nicely.
comment:29 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:30 by , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | assigned → new |
comment:31 by , 14 years ago
| Cc: | added |
|---|---|
| Easy pickings: | unset |
| UI/UX: | unset |
(In [10346]) Fixed #9847: mark the permission denied message for translation.