django-context refers to the special django.template.Context class used for passing data from the view to the template
Questions tagged [django-context]
171 questions
3
votes
1 answer
Django template context function without running automatically
Sorry or the confusing title! It's actually a lot simpler than it sounds.
I've got a function:
def get_messages(request):
# do something expensive with the request
return 'string'
I want to be able to call that function from the template,…

Oli
- 235,628
- 64
- 220
- 299
3
votes
1 answer
Read request variable in template tag
I am in the process of turning a Django project into a multi-language site. For that purpose I am trying to adopt the countries-for-django (github) package.
In one of the templatetags, the code is trying to read the session variable django_country…

neurix
- 4,126
- 6
- 46
- 71
3
votes
3 answers
Django TEMPLATE_CONTEXT_PROCESSORS are being called too many times
I need show some statistic numbers in all pages, so I decided to use context processors. But I just figured out that my function is being called 2 to 7 times every page load. I am doing 4 queries inside the function, so I am getting a very bad…

Thomas
- 2,256
- 6
- 32
- 47
3
votes
2 answers
Access to RequestContext in Django template?
I don't seem to have access to the request object in my django templates.
Here's part of my settings.py file:
import django.conf.global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSOR = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
…

Joshua Kravitz
- 2,785
- 2
- 15
- 15
3
votes
1 answer
Can I add more than two arguments to get_context_data()?
I get this error
TypeError at /debate/1/
get_context_data() takes exactly 2 arguments (1 given)
Right now it is defined as:
def get_context_data(self, **kwargs):
And I want it to be:
def get_context_data(self, request, **kwargs):
so I can do…

tamara
- 120
- 1
- 12
2
votes
3 answers
Django - Access Context Dictionary Before Template
I'm hoping to use a context processor or middleware to modify the values of the dictionary passed to render_to_response prior to the actual rendering. I have a messaging schema I'm trying to implement that would populate a message list based on the…

garromark
- 814
- 8
- 20
2
votes
1 answer
Django 'context' for function-based and class-based views
Help me understand how to use Django's context--Is the issue related to the use of context in function-based vs class-based views:
I have created two views (index and post_list) and respective templates (following the Assessment portion of the…

YCode
- 1,192
- 1
- 12
- 28
2
votes
2 answers
RequestContext on django redirect()
I'm wondering if there is any way to include the RequestContext in the django redirect function or any other context.
The thing is that I need to add a message after an object is created, but the messages framewotk requires a RequestContext to work…

CastleDweller
- 8,204
- 13
- 49
- 69
2
votes
2 answers
Django admin add context to index.html
I'm trying to override Django admin index.html to show table contain latest 5 records from a model
I managed to override the template with the following in my app:
from django.contrib import admin
admin.site.index_template =…

Linh Nguyen
- 3,452
- 4
- 23
- 67
2
votes
0 answers
Setting individual context data in a listview queryset
I am working on a film review system in Django and I am stuck with my upvote/like system. On my detail view I have:
class ReviewDetailView(DetailView):
model = Review
template_name = 'review.html'
def get_context_data(self, *args,…

Ross
- 21
- 3
2
votes
1 answer
In Django, how to implement boilerplate HTML variables with Dynamic URLs used in templates and DB objects?
In Django, in my DB I've created string variables containing boilerplate HTML with dynamic URLs, and I can't quite get them to work in my templates.
I'm using render_as_template…

brized
- 51
- 8
2
votes
1 answer
Custom context processor doesn't work
I have the following code:
1) context processor
def defaults(request):
return {
'LOGO_DEFAULT_SRC': LOGO_DEFAULT_CSRC
}
2) settings
'OPTIONS': {
'context_processors': [
…

user3541631
- 3,686
- 8
- 48
- 115
2
votes
1 answer
django context with several inclusion_tag
I have a little problem with the context.
I have an inclusion tag with the param :
takes_context=True
In this inclusion's tag's template, I call for another inclusion_tag which has also the param
takes_context = True
But in this last inclusion_tag…

rodriguez
- 21
- 1
2
votes
1 answer
Django form fields will not display
I am following the Django Fundamentals tutorial on Code School and I've done pretty well understanding, following along, and figuring out my own issues as they arise, until this point. The tutorial builds a tic-tac-toe game.
I am trying to add the…

e-beth
- 77
- 1
- 3
- 9
2
votes
1 answer
Django context not rendering
I've got a Django template in HTML. I would like to pass a variable to this template using a context. However, when I render the template Django fills the spaces that reference this variable with the string specified by the…

Forkstealer
- 21
- 1
- 4