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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현