Help needed - new very first django App

조회수 28회
읽지 않은 첫 메시지로 건너뛰기

Jayaram Namburaj

읽지 않음,
2018. 2. 28. 오후 12:52:4718. 2. 28.
받는사람 Django users
Hi All,

I am very new to django framework ( just 2 days)
I am referring django tutorial pdf for my self learning.
Right now I am stuck at my very first program using Django Template Language (DTL) .

Please find the below code just for your reference:

urls.py  ( Application )
---------
from django.urls import path
from . import views

urlpatterns = [
               path('dispWelcomePage/', views.myWelcomepage, name='myWelcomepage'),
      path('secondPage/', views.mySecondpage),
      path('pagenum/', views.dispInputParam),
               path('exRender/',views.exampleRenderFunc),
      path('exRenderDict/',views.passDictValues)
               ]
     
     
     
views.py  ( Application )
----------
from django.shortcuts import render
from django.http import HttpResponse

def passDictValues(request):
    mylist=['a','b','c','d']
    empDetails={'name':'ABCD','city':'xyz','age':'30','gender':'M','MyListArg':mylist}
    return render(request,'myapp/RenderDictParams.html',empDetails)

  
RenderDictParams.html:
--------------------------------
<html>
<body>
   <h3>This is Render Method Example with Python Dictionary as Arguments!! </h3>
   Testing_1<br>
   {% for val in mylist %}
    {{ val }}
   {% endfor %}  
   Testing_2
   </body>
</html>


When running the url  http://127.0.0.1:8000/myapp/exRenderDict/ output doesn't display the values which is from the for loop.
(Please find the attached file just for you reference )
My django verion : 2.0.1
Python version : 3.6.0
Please you help me if possible to sort out this.
Let me know if I am missing anything or any further details needed.

Thanks for your support
Regards
JayaramN




django_files.pptx

Kasper Laudrup

읽지 않음,
2018. 2. 28. 오후 1:11:2718. 2. 28.
받는사람 django...@googlegroups.com
Hi Jayaram,

On 2018-02-28 15:45, Jayaram Namburaj wrote:
>
> When running the url http://127.0.0.1:8000/myapp/exRenderDict/ output
> doesn't display the values which is from the for loop.

You named your list 'MyListArg' not 'mylist' in the dictionary you
passed to the render function.

Try changing this:

{% for val in mylist %}

To:

{% for val in MyListArg %}

That should hopefully fix it. I haven't tested it though.

Kind regards,

Kasper Laudrup

Jayaram Namburaj

읽지 않음,
2018. 3. 1. 오전 7:33:3118. 3. 1.
받는사람 Django users
Hi Kasper,

Thanks for your findings.
It is working now as per your suggestion.

Regards
JayaramN
전체답장
작성자에게 답글
전달
새 메시지 0개