0

In my urls.py, I direct traffic like this:

url(r'^basic/', 'mysite.views.basicHandler', name='basic'),

Which is handled in my views.py like this:

from django.shortcuts import render_to_response as dr2r

def basicHandler( request ):
    rc = RequestContext(request, {
        "cdn_url" : settings.CDN_BASE_URL,
        "cdn_home" : settings.CDN_SITE_PATH
    })
    return dr2r( 'basic.html', {}, context_instance=rc )

My question is, how can my views handler (basicHandler) access the url pattern (r'^basic/')? Is that inside of the request object?

1 Answer 1

1

Yes, you can get it from the request.META object.

referer = request.META.get('HTTP_REFERER')

Alternatively, you can resolve the URL using reverse() method

from django.core.urlresolvers import reverse

url = reverse('basic')
Sign up to request clarification or add additional context in comments.

2 Comments

reverse worked (returned /basic/), but the HTTP_REFERER did not (returned None) ... any ideas what might cause that?
HTTP_REFERER, if present in the request at all, would be the URL of the previous page, not the current page. request.path and request.path_info are where I'd start. request.resolver_match might also be useful, depending on exactly what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.