Get reverse URL name from full path

Marcos Aguayo

Does anyone knows how I can get the URL name from the request.get_full_path()?

For example:

I have this URL in urls.py

url(r'^evaluation-active/$', 'web.evaluation.evaluation', name='evaluation'),

In my context_processor.py:

def is_evaluation(request):
    return {"test":request.get_full_path()}

How can I return "evaluation" instead of "/evaluation-active/"?

Thanks

ndpu

From django docs:

HttpRequest.resolver_match

New in Django 1.5. An instance of ResolverMatch representing the resolved url. This attribute is only set after url resolving took place, which means it’s available in all views but not in middleware methods which are executed before url resolving takes place (like process_request, you can use process_view instead).

There is url_name attribute in ResolverMatch object:

def is_evaluation(request):
    return {"test": request.resolver_match.url_name}

For django version < 1.5 there is answer here: How to get the current urlname using Django?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get reverse URL name from full path

From Dev

Get List Name from full url

From Dev

Get directory name from full directory path regardless of trailing slash

From Dev

Get Image name from full image path using PHP

From Dev

How to get only path from full url string

From Dev

Twitter reverse auth get full name

From Dev

Parse file name and path from full path

From Dev

Get the full formatted address from Reverse Geocoding

From Dev

react router get full current path name

From Dev

Python cant get full path name of file

From Dev

How to get full path name of a Linux command

From Dev

get domain name only in not full path

From Dev

get domain name only in not full path

From Dev

Get current name for path in url

From Dev

Extract a file name from the full file path

From Dev

awk: Extracting file name from full path

From Dev

awk: Extracting file name from full path

From Dev

How to get the full URL with the current path in Capybara

From Dev

How to get the full URL with the current path in Capybara

From Dev

Get users SAMaccount name from Full name

From Dev

How can I get file's name from variable with its full path in python?

From Dev

How can I get file tile(name) from file full path in VB6?

From Dev

Django : extract a path from a full URL

From Dev

Django : extract a path from a full URL

From Dev

Extracting directory path from full file path without the file name

From Dev

Get file name from path

From Dev

Get full path to file from argument

From Dev

Get full path from command line in assembly

From Dev

Get full file path from GtkTreeView