Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

The automatic breadcrumbs don't work when WSGIScriptAlias isn't "/" #211

Closed
wants to merge 1 commit into from

3 participants

@ncoghlan

As per https://code.djangoproject.com/ticket/10328, the Django-relative part of the URL is stored in the requests "path_info" attribute, while the "path" attribute also includes the WSGIScriptAlias portion.

The breadcrumb generator is currently using the wrong one, and hence all of the calls to "resolve()" fail with a 404 and no breadcrumbs are reported.

@ncoghlan

It turns out the patch in this pull request isn't sufficient - the breadcrumbs it generates are missing the prefix from the returned URLs

@ncoghlan

To get usable breadcrumbs when serving pages from a location other than the root URL, I had to do the following:

    broken_crumbs = get_breadcrumbs(request.path_info)
    prefix = request.path[:-len(request.path_info)]
    crumbs = [(crumb_name, prefix + crumb_url)
                 for crumb_name, crumb_url in broken_crumbs]
@mammique

I fix this in my 'prod' fork, here: mammique@9c160be

Camille.

@tomchristie
Owner

I believe .get_script_prefix() is the proper way to do this.

@tomchristie
Owner

Anyone care to review the pull req I've made?

@tomchristie
Owner

And, uh, apologies for the delay! :)
Getting on top of this all again, now.

@mammique

I'll try to test this tonight, I keep you posted. Thanks.

@tomchristie
Owner
@tomchristie
Owner
@mammique

Ah, OK, it will take a bit longer then. The only instance I have that isn't running under / is in production mode, I cannot make such deep changes now. I should better try to deploy an nginx subpath instance while testing 2.0. I tell you as soon as I can test.

Camille.

@tomchristie
Owner

Also pushed to master.
Will push a 0.4.1 release shortly as the final release prior to the 2.0 launch.

@phobologic phobologic referenced this pull request from a commit in phobologic/django-rest-framework
@tomchristie Breadcrumbs play nicely when app not installed at root URL. Fixes #211 aba9170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  djangorestframework/renderers.py
View
2  djangorestframework/renderers.py
@@ -329,7 +329,7 @@ def render(self, obj=None, media_type=None):
name = self.get_name()
description = self.get_description()
- breadcrumb_list = get_breadcrumbs(self.view.request.path)
+ breadcrumb_list = get_breadcrumbs(self.view.request.path_info)
template = loader.get_template(self.template)
context = RequestContext(self.view.request, {
Something went wrong with that request. Please try again.