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
1
vote
1 answer
Is there a shorter way to check for a value in M2M in a Django template?
In every page (base.html), I want to check whether request.user has an administrator role from my class UserTypes and show the admin link. Currently I do something like this:
{% if user.profile.user_types.all %}
{% for user_type in…

hobbes3
- 28,078
- 24
- 87
- 116
0
votes
1 answer
How can I get the template context from the template loader in Django?
I need to load some templates which path depends of their context. I created a custom Loader. How can I access to the context of the template from my custom template loader?

Jorge Barata
- 2,227
- 1
- 20
- 26
0
votes
1 answer
A thread-safe template context processor in Django?
What is the best practice for writing a thread-safe context processor in Django?
Say, I want to pass some variables to templates, which
are set in the corresponding views, and could be different for
different view-template pairs.
One solution would…

krishnapp
- 3
- 1
0
votes
1 answer
Change to my left nav bar when on a certain page?
Maybe I'm going about this all the wrong way... But what I'm trying to do is change the left navigation by what page I'm on. The left nav in base.html is apparent throughout, but once the user is on forums.html (extends base.html), I wanted to have…

Modelesq
- 5,192
- 20
- 61
- 88
0
votes
0 answers
Trouble passing Django request.POST.get() variables to context after AJAX
I am in a quite strange situation. I have this form:
0
votes
2 answers
Django: How to reference a context variable created in one class-based view from another class-based view
In the simplified example below, how do I reference the context variable "Elephant" (created in the class Lion) from inside the class Leopard?
I have researched and tried a number of ways, including the last line below which results in a KeyError…

Condado
- 83
- 7
0
votes
0 answers
Add an item with multiple variations to basket in Django
I have a views.py and contexts.py that adds a product with a particular flavour to the basket on my Django site. I have copied this logic from a course I'm on. I now want to be able to have multiple variations on products and add them to my basket.…

ladcode2022
- 31
- 5
0
votes
1 answer
For loop and with tag in a Django template
I have a context built in this way:
def end(request):
numero_debitori = request.session['numero_debitori']
dati_totali = {'numero_debitori': numero_debitori}
if request.session['tipo_creditore'] == 'PF':
dati_totali['creditore']…

Andrea
- 61
- 6
0
votes
2 answers
for loop in django template returning blank list items
I'm looping through the field of joined for my Group model and returning the list of joined members in my GroupDetail template:
class Group(models.Model):
leader = models.ForeignKey(User, on_delete=models.CASCADE)
name =…

Yehuda
- 27
- 15
0
votes
1 answer
Django access site name/url in template - views, contexts and settings
(It feels like "best practices" type of question, sorry if these don't belong here)
I'm building a website which has user registration and password reset feature, both of which would send email to the user with a link to click to complete the…

alexakarpov
- 1,848
- 2
- 21
- 39
0
votes
0 answers
unable to add model in custom context processor django
In my django project, I need to pass certain details from couple of models to all the views and realized that the best way to do this would be create a custom context processor file.
the context processor works fine when passing harcoded values but…

Irfan Harun
- 979
- 2
- 16
- 37
0
votes
3 answers
Loop through nested dictionary
I have nested dictionary which look like this:
{
'location': {0: 'London', 1: 'London', 2: 'London', 3: 'London', 4: 'London', 5: 'London', 6: 'London'},
'attraction': {0: 'museum', 1: 'museum', 2: 'museum', 3: 'museum', 4: 'museum', 5: 'museum',…

konrad8767
- 139
- 6
0
votes
0 answers
Adding a conditional context to a function to work in a Django Template
I have a Django form and I am trying show text only once the form is successfully completed
I added context so that when the form is successfull successful_submit is true and in the template I add a conditional to only show the text once it is…

A_K
- 731
- 3
- 15
- 40
0
votes
0 answers
I want to show each games title in its specific platform in the navbar(no one answered, I have shown the full error as an answer )
I want to show each games title in its specific platform in the navbar by creating a GameManager with a function called 'show_pc_game' which will only show games whose platform is PC.
This is my models.py:
class GameManager(models.Manager):
def…

saleh
- 315
- 1
- 12
0
votes
1 answer
Use context variable to compare with forloop.revcounter in Django
I can not use context variable to compare with forloop.counter or forloop.revcounter. No error returning. But, every time if statement become false.
here is my view func-
def view_single_server(request, pk):
server =…

Samrat
- 83
- 1
- 5