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
0
votes
0 answers
How do I get Django's 'context' variables accessible to more than one view?
Is it possible to have the variables of a context block accessible to more than one view? Can one create "constants" in Django 'views.py'?
I have two pages: 'index.html' and 'post_list.html'. They both use the model 'Post', but the two pages aren't…

YCode
- 1,192
- 1
- 12
- 28
0
votes
0 answers
How do these different Django 'context' construction differ?
The basic concept of context in Django are well explained here and here, as well as Django doc. But I don't understand the following code that works in the Mozilla Django tutorial:
class BookListView(generic.ListView):
model = Book
def…

YCode
- 1,192
- 1
- 12
- 28
0
votes
2 answers
Django context processor throw error on redirect
I'm using the following context processor to pass context to all my pages, except when the user is not logged in which case it takes him to the login page :
from django.conf import settings
from .models import foo
from django.shortcuts import…

S P H I N X U S
- 5
- 3
0
votes
1 answer
Django: How to search through django.template.context.RequestContext
I'm working over tests in Django and faced , which I'm trying to iterate through and find object inside.
test.py
def test_ProductDetail_object_in_context(self):
…

NatalieLes
- 153
- 9
0
votes
1 answer
How to use sekizai's addtoblock tag inside a form widget template
I am writing a custom form field which has a custom widget. The widget needs some static assets. Its template looks like this:
{% load sekizai_tags static %}
...
{% addtoblock "css" %}

fekioh
- 894
- 2
- 9
- 22
0
votes
1 answer
ImportError at / Module "cart.context" does not define a "cart_context" attribute/class
Im trying to create a django cart page. im having an issue adding products/plans to a cart and im also having an issue on showing a quantity of items in the cart. Ive made a context.py to try add to the cart but im not too sure what im doing wrong.…

amit238
- 21
- 4
0
votes
1 answer
Following relationships "backward" in context processor
I did template processor uses the backward following relationship. In the shell it works OK, but in the view I have an error:
'ParentCategory' object has no attribute 'postpages_set'
model (a little simpler than the original)
class…

I159
- 29,741
- 31
- 97
- 132
0
votes
1 answer
How to access individual fields with of customised User model using AbstractUser?
I have defined a user model inheriting AbstractUser from django.auth.models. How can I refer to each individual fields of that customized user model? Say if I want to refer to date of birth of the customised user what should I write? I need to show…

Sandip Nath
- 622
- 2
- 8
- 18
0
votes
1 answer
pagination of a specific context in multiple context in ListView not working in django?
in django, i am trying to list some queries of several objects like user lists, categoies and Post list. the homepage will be contained couple of blocks or boxes. each box will have different query list like Post list, User List, category list. But…

rony01
- 131
- 10
0
votes
1 answer
DJango Passing in POST as a Context Argument
When making views in django, is it allowable to pass in POST data as context? That is:
def view( request ):
#view operations here
#...
c = Context({
'POST':request.POST,
})
return render_to_response("/templatePath/", c,…

WonderBoy55
- 41
- 1
- 3
- 6
0
votes
1 answer
How can I display different results onto separate templates from one model in Django, using class based views?
I have one model:
class Product(models.Model):
slug = models.SlugField(unique=True)
image = models.ImageField(upload_to='media')
title = models.CharField(max_length=150)
description = models.TextField()
short_description =…

CThomas
- 199
- 1
- 10
0
votes
1 answer
Django context Datetime unique date
I have in my model one DateTimeField like this
timestamp = models.DateTimeField(auto_now=True)
I want to filter the displayed results in the template by date, but each date only once and the time not at all.
in my views,
def get_context_data(self,…

Snowball
- 35
- 5
0
votes
2 answers
Django object "lock" and context rendering
I have a simple(I think) question, about Django context rendering.
I'll step right into it -
Basically what I need is, some temp table, which in my case, I called Locked. And when a user presses a button, which Is a form, that object goes straight…

dev.ink
- 380
- 5
- 21
0
votes
3 answers
Is it possible automatically include user to all templates?
I have project in Django 1.3. In order to show username in all pages I use such tags in base.html
{% if user.is_authenticated %}
Welcome, {{ user.username }}. loggout
{% else %}
Daler
- 814
- 14
- 28
0
votes
1 answer
I'm trying to incorporate multiple models into a single django view; how can I access the context **kwargs
I've tried this:
class MyClass(LoginRequiredMixin, UpdateView, ListView):
model = models.my_model
fields = ['first_model_field', 'second_model_field']
template_name = 'app/template_name.html'
extra_context = {'second_model':…

Lunaugh
- 25
- 7