Why passing arguments to parent template makes the child template not be able to use themDjango: Passing argument to parent templateChanging the child element's CSS when the parent is hoveredDjango & AJAX Changing Div ContentsHow to send request from one django server to another serverHow do I pass a parent id as an fk to child object's ModelForm using generic class-based views in Django?How can I use placeholder in a Django template translation using the lazy syntax?Django redirects to login page even after logging inHow save specific user instance into database using django viewsPassing variables into extends template?Pulling data from db causing 404 page not found error
How to make attic easier to traverse?
Did Captain America make out with his niece?
split large formula in align
Best way to explain to my boss that I cannot attend a team summit because it is on Rosh Hashana or any other Jewish Holiday
Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?
Plato and the knowledge of the forms
Make a living as a math programming freelancer?
Where to pee in London?
Find a text string in a file and output only the rest of the text that follows it?
Did Apollo leave poop on the moon?
Is the first page of a novel really that important?
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Why do dragons like shiny stuff?
What does the ISO setting for mechanical 35mm film cameras actually do?
Why should I "believe in" weak solutions to PDEs?
What's going on with an item that starts with an hbox?
Find only those folders that contain a File with the same name as the Folder
What could prevent players from leaving an island?
Is space radiation a risk for space film photography, and how is this prevented?
Getting Lost in the Caves of Chaos
Is a switch from R to Python worth it?
Pronouns when writing from the point of view of a robot
Why does capacitance not depend on the material of the plates?
Is an "are" omitted in this sentence
Why passing arguments to parent template makes the child template not be able to use them
Django: Passing argument to parent templateChanging the child element's CSS when the parent is hoveredDjango & AJAX Changing Div ContentsHow to send request from one django server to another serverHow do I pass a parent id as an fk to child object's ModelForm using generic class-based views in Django?How can I use placeholder in a Django template translation using the lazy syntax?Django redirects to login page even after logging inHow save specific user instance into database using django viewsPassing variables into extends template?Pulling data from db causing 404 page not found error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
im making a django project for school website
I have a base.html that acts as parent template for the child templates which is the content of every page
The base.html includes a navbar with the school logo and a section on it titled "Units"
this is the code to render a lecturer page
views.py
.
.
def lecturer_home(request):
user = request.user
query for the user first name and full name
query for the units that the user is teaching and their teaching
period in unit_list and period_display
class_display = zip(unit_list, period_display)
user_dict =
'f_name' : user.first_name,
'fl_name' : user.first_name + ' ' + user.last_name,
'class_display' : class_display,
return render(request, 'Lecturer/lecturerdashboard.html', user_dict)
else:
return HttpResponse('Unexpected error')
lecturerdashboard.html extends the base.html
I put less code for my views.py because I don't think I made any errors. What I want to confirm with you all is, the user_dict I passed in lecturerdashboard.html can also be used in the base.html, but confusingly I find that if a key and value is used in either one, the other one cannot use it.
for example, I am able to display the units in the content section in the lecturerdashboard.html but when I used class_display in the base.html to show units as dropdown menu selection when the lecturer click on Units, the content section will not work because it doesnt understand class_display.
sorry if the question is confusing
in summary, the parent and child understands the argument passed by the view but if a key, value is used in parent, the child does not understand it
i just want to confirm, is this true?
thank you
django parent extends
add a comment |
im making a django project for school website
I have a base.html that acts as parent template for the child templates which is the content of every page
The base.html includes a navbar with the school logo and a section on it titled "Units"
this is the code to render a lecturer page
views.py
.
.
def lecturer_home(request):
user = request.user
query for the user first name and full name
query for the units that the user is teaching and their teaching
period in unit_list and period_display
class_display = zip(unit_list, period_display)
user_dict =
'f_name' : user.first_name,
'fl_name' : user.first_name + ' ' + user.last_name,
'class_display' : class_display,
return render(request, 'Lecturer/lecturerdashboard.html', user_dict)
else:
return HttpResponse('Unexpected error')
lecturerdashboard.html extends the base.html
I put less code for my views.py because I don't think I made any errors. What I want to confirm with you all is, the user_dict I passed in lecturerdashboard.html can also be used in the base.html, but confusingly I find that if a key and value is used in either one, the other one cannot use it.
for example, I am able to display the units in the content section in the lecturerdashboard.html but when I used class_display in the base.html to show units as dropdown menu selection when the lecturer click on Units, the content section will not work because it doesnt understand class_display.
sorry if the question is confusing
in summary, the parent and child understands the argument passed by the view but if a key, value is used in parent, the child does not understand it
i just want to confirm, is this true?
thank you
django parent extends
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45
add a comment |
im making a django project for school website
I have a base.html that acts as parent template for the child templates which is the content of every page
The base.html includes a navbar with the school logo and a section on it titled "Units"
this is the code to render a lecturer page
views.py
.
.
def lecturer_home(request):
user = request.user
query for the user first name and full name
query for the units that the user is teaching and their teaching
period in unit_list and period_display
class_display = zip(unit_list, period_display)
user_dict =
'f_name' : user.first_name,
'fl_name' : user.first_name + ' ' + user.last_name,
'class_display' : class_display,
return render(request, 'Lecturer/lecturerdashboard.html', user_dict)
else:
return HttpResponse('Unexpected error')
lecturerdashboard.html extends the base.html
I put less code for my views.py because I don't think I made any errors. What I want to confirm with you all is, the user_dict I passed in lecturerdashboard.html can also be used in the base.html, but confusingly I find that if a key and value is used in either one, the other one cannot use it.
for example, I am able to display the units in the content section in the lecturerdashboard.html but when I used class_display in the base.html to show units as dropdown menu selection when the lecturer click on Units, the content section will not work because it doesnt understand class_display.
sorry if the question is confusing
in summary, the parent and child understands the argument passed by the view but if a key, value is used in parent, the child does not understand it
i just want to confirm, is this true?
thank you
django parent extends
im making a django project for school website
I have a base.html that acts as parent template for the child templates which is the content of every page
The base.html includes a navbar with the school logo and a section on it titled "Units"
this is the code to render a lecturer page
views.py
.
.
def lecturer_home(request):
user = request.user
query for the user first name and full name
query for the units that the user is teaching and their teaching
period in unit_list and period_display
class_display = zip(unit_list, period_display)
user_dict =
'f_name' : user.first_name,
'fl_name' : user.first_name + ' ' + user.last_name,
'class_display' : class_display,
return render(request, 'Lecturer/lecturerdashboard.html', user_dict)
else:
return HttpResponse('Unexpected error')
lecturerdashboard.html extends the base.html
I put less code for my views.py because I don't think I made any errors. What I want to confirm with you all is, the user_dict I passed in lecturerdashboard.html can also be used in the base.html, but confusingly I find that if a key and value is used in either one, the other one cannot use it.
for example, I am able to display the units in the content section in the lecturerdashboard.html but when I used class_display in the base.html to show units as dropdown menu selection when the lecturer click on Units, the content section will not work because it doesnt understand class_display.
sorry if the question is confusing
in summary, the parent and child understands the argument passed by the view but if a key, value is used in parent, the child does not understand it
i just want to confirm, is this true?
thank you
django parent extends
django parent extends
edited Mar 27 at 3:36
JPG
22k3 gold badges13 silver badges46 bronze badges
22k3 gold badges13 silver badges46 bronze badges
asked Mar 27 at 3:34
nanakondornanakondor
387 bronze badges
387 bronze badges
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45
add a comment |
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45
add a comment |
2 Answers
2
active
oldest
votes
This doesn't really have anything to do with templates. zip
is an iterator. Once you iterate through it, it is exhausted, and can't be used again. If you want to iterate it multiple times, call list
on it:
class_display = list(zip(unit_list, period_display))
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
add a comment |
I don't know if I understood clearly:
You want to have access to some of the variables like class_display in every template ?
If so the best solution for that is to use Context Processors. Example:
- Create file in your app for example context_processors.py
from users.models import UserMessage
def notifications(request):
if not request.user.is_anonymous:
notifications = UserMessage.objects.filter(
receiver=request.user, read=False)
ctx =
"notifications": notifications,
"notifications_number": notifications.count()
return ctx
return
- In settings.py in
TEMPLATES --> 'context_processors' add:
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS':
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app_name.context_processors.notifications' # added this!
],
,
,
]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369392%2fwhy-passing-arguments-to-parent-template-makes-the-child-template-not-be-able-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This doesn't really have anything to do with templates. zip
is an iterator. Once you iterate through it, it is exhausted, and can't be used again. If you want to iterate it multiple times, call list
on it:
class_display = list(zip(unit_list, period_display))
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
add a comment |
This doesn't really have anything to do with templates. zip
is an iterator. Once you iterate through it, it is exhausted, and can't be used again. If you want to iterate it multiple times, call list
on it:
class_display = list(zip(unit_list, period_display))
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
add a comment |
This doesn't really have anything to do with templates. zip
is an iterator. Once you iterate through it, it is exhausted, and can't be used again. If you want to iterate it multiple times, call list
on it:
class_display = list(zip(unit_list, period_display))
This doesn't really have anything to do with templates. zip
is an iterator. Once you iterate through it, it is exhausted, and can't be used again. If you want to iterate it multiple times, call list
on it:
class_display = list(zip(unit_list, period_display))
answered Mar 27 at 6:54
Daniel RosemanDaniel Roseman
477k43 gold badges611 silver badges669 bronze badges
477k43 gold badges611 silver badges669 bronze badges
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
add a comment |
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!
– nanakondor
Mar 27 at 8:52
add a comment |
I don't know if I understood clearly:
You want to have access to some of the variables like class_display in every template ?
If so the best solution for that is to use Context Processors. Example:
- Create file in your app for example context_processors.py
from users.models import UserMessage
def notifications(request):
if not request.user.is_anonymous:
notifications = UserMessage.objects.filter(
receiver=request.user, read=False)
ctx =
"notifications": notifications,
"notifications_number": notifications.count()
return ctx
return
- In settings.py in
TEMPLATES --> 'context_processors' add:
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS':
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app_name.context_processors.notifications' # added this!
],
,
,
]
add a comment |
I don't know if I understood clearly:
You want to have access to some of the variables like class_display in every template ?
If so the best solution for that is to use Context Processors. Example:
- Create file in your app for example context_processors.py
from users.models import UserMessage
def notifications(request):
if not request.user.is_anonymous:
notifications = UserMessage.objects.filter(
receiver=request.user, read=False)
ctx =
"notifications": notifications,
"notifications_number": notifications.count()
return ctx
return
- In settings.py in
TEMPLATES --> 'context_processors' add:
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS':
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app_name.context_processors.notifications' # added this!
],
,
,
]
add a comment |
I don't know if I understood clearly:
You want to have access to some of the variables like class_display in every template ?
If so the best solution for that is to use Context Processors. Example:
- Create file in your app for example context_processors.py
from users.models import UserMessage
def notifications(request):
if not request.user.is_anonymous:
notifications = UserMessage.objects.filter(
receiver=request.user, read=False)
ctx =
"notifications": notifications,
"notifications_number": notifications.count()
return ctx
return
- In settings.py in
TEMPLATES --> 'context_processors' add:
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS':
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app_name.context_processors.notifications' # added this!
],
,
,
]
I don't know if I understood clearly:
You want to have access to some of the variables like class_display in every template ?
If so the best solution for that is to use Context Processors. Example:
- Create file in your app for example context_processors.py
from users.models import UserMessage
def notifications(request):
if not request.user.is_anonymous:
notifications = UserMessage.objects.filter(
receiver=request.user, read=False)
ctx =
"notifications": notifications,
"notifications_number": notifications.count()
return ctx
return
- In settings.py in
TEMPLATES --> 'context_processors' add:
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS':
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app_name.context_processors.notifications' # added this!
],
,
,
]
answered Mar 27 at 6:50
MikeyMikey
1615 bronze badges
1615 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369392%2fwhy-passing-arguments-to-parent-template-makes-the-child-template-not-be-able-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi nanakondor , it would depend on how you are using the values passed by views in a template. If you could post the code in template demonstrating use of class_display we may be able to shed some light on the issue.
– SwapnilBhate
Mar 27 at 4:45