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;








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










share|improve this question


























  • 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

















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










share|improve this question


























  • 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













0












0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












2 Answers
2






active

oldest

votes


















0














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))





share|improve this answer

























  • o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!

    – nanakondor
    Mar 27 at 8:52


















0














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:



  1. 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


  1. 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!
],
,
,
]





share|improve this answer



























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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))





    share|improve this answer

























    • o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!

      – nanakondor
      Mar 27 at 8:52















    0














    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))





    share|improve this answer

























    • o yeah this is the solution to my problem ty very much!!!!!!!!!!!!!!!!

      – nanakondor
      Mar 27 at 8:52













    0












    0








    0







    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))





    share|improve this answer













    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))






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • 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













    0














    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:



    1. 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


    1. 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!
    ],
    ,
    ,
    ]





    share|improve this answer





























      0














      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:



      1. 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


      1. 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!
      ],
      ,
      ,
      ]





      share|improve this answer



























        0












        0








        0







        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:



        1. 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


        1. 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!
        ],
        ,
        ,
        ]





        share|improve this answer













        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:



        1. 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


        1. 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!
        ],
        ,
        ,
        ]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 6:50









        MikeyMikey

        1615 bronze badges




        1615 bronze badges






























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript