Django: Display Choice Value
It looks like you were on the right track – get_FOO_display() is most certainly what you want: In templates, you don’t include () in the name of a method. Do the following: {{ person.get_gender_display }}
It looks like you were on the right track – get_FOO_display() is most certainly what you want: In templates, you don’t include () in the name of a method. Do the following: {{ person.get_gender_display }}
Django provides it. You can use either: {{ forloop.counter }} index starts at 1. {{ forloop.counter0 }} index starts at 0. In template, you can do: {% for item in item_list %} {{ forloop.counter }} # starting index 1 {{ forloop.counter0 }} # starting index 0 # do your stuff {% endfor %} More info … Read more
Django 1.9 and above: ## template {{ request.path }} # -without GET parameters {{ request.get_full_path }} # – with GET parameters Old: ## settings.py TEMPLATE_CONTEXT_PROCESSORS = ( ‘django.core.context_processors.request’, ) ## views.py from django.template import * def home(request): return render_to_response(‘home.html’, {}, context_instance=RequestContext(request)) ## template {{ request.path }}
If it’s a value you’d like to have for every request & template, using a context processor is more appropriate. Here’s how: Make a context_processors.py file in your app directory. Let’s say I want to have the ADMIN_PREFIX_VALUE value in every context: from django.conf import settings # import the settings file def admin_media(request): # return … Read more