search
menu
person

NEWS AND UDATES


17:12
Передать текущий url в шаблон

Ответ на англ.

A:

Is there a way to get the current page URL and all its parameters in a Django template?

For example, a templatetag that would print full URL like /foo/bar?param=1&baz=2

Q

Write a custom context processor. e.g.

def get_current_path(request):
 return {
 'current_path': request.get_full_path()
 }

add a path to that function in your TEMPLATE_CONTEXT_PROCESSORS settings variable, and use it in your template like so:

{{ current_path }}

If you want to have the full request object in every request, you can use the built-indjango.core.context_processors.request context processor, and then use {{ request.get_full_path }} in your template.

See:

Просмотров: 2039 | Добавил: django | Рейтинг: 0.0/0
Всего комментариев: 2
0  
1 Богдан   (18.01.2014 23:32) [Материал]
Либо просто использовать код $HOME_PAGE_LINK$$REQUEST_URI$

0  
2 django   (30.04.2014 15:01) [Материал]
тут речь идет о python, вы судя по $ предлагаете решение для php, хотя кому-то это будет тоже полезно)

dth="100%" cellspacing="1" cellpadding="2" class="commTable">
Имя *:
Email:
Код *: