开发者

Get the currently used url when an on the template in django for us in a breadcrumb?

I have an app which serves two purposes - displays members and centres of my company. They both work exactly the same, save a different variable when filtering my model. Problem is I can't get the current url onto the template to use in my custom breadcrumbs.


I have this urlpattern in my main urls.py:

# --- urls.py ---- 
url(r'^find-member/', include('company.directory.urls'), \
        {'which_app': 'members'}, name='find_member'),
url(r'^find-centre/', include('company.directory.urls'), \
        {'which_app': 'training'}, name='find_centre'),

of which links to my app urls.py:

# ---- company/urls.py ----
from django.conf.urls.defaults import *
urlpatterns = patterns('company.directory.views',
    url(r'^$', 'index'),
    url(r'^(?P<slug>\w+)/$', 'index'),
)

on my template I wish to create a link to the first urlpatten for use with my custom breadcrumbs

<a href='/find-member/'>members</a>

or

<a href='/find-centre/'>Centre</a> 

based upon which url I'm using the app with.

my view looks like this:

# ---- company/view.py ----
def index(request, which_app=None, slug=None):
    #r = reverse('' ,kwargs={'which_app'=training )
    s = "%s %s" % (which_app, slug)

    return render_to_response('directory/index.html', locals())

I would like to find the url based upon the which_app variable passed into the def. I can't seem to use resolve() or reverse(开发者_StackOverflow). I'm probably doing it wrong. I haven't really got a template to show right now.

Does anybody have any suggestions? I'd love some advice.

Thanks in advance.


You don't need to use a function. Your view is passed the request object, which has an attribute path which is the path that was called. See the request docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜