Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check type of reverse_lazy() object in django

I want to do following:

u=reverse_lazy('xyz')
isinstance(u,str) # this is false since u is an object.

type(u) # <class 'django.utils.functional.lazy.<locals>.__proxy__'>

isinstance(u,<class 'django.utils.functional.lazy.<locals>.__proxy__'>) # doesnt work

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Doing u.__dict__ you will get the following dict:

{'_proxy____args': ('xyz',), '_proxy____kw': {}}

With that, you can get the initial args and then get the types of them.

u=reverse_lazy('xyz')

initial_arg = u._proxy____args[0]

print(initial_arg)
# 'xyz'

print(type(initial_arg))
# <class 'str'>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading