-1

i'm trying to get the data from my views.py to the html page. if the views.py code is this

def VerifiedBySuperuser(request):
if request.method == 'POST':
        vbs = MaanyaIT_EXAM48_ManageQuestionBank()
        vbs.QuestionID = MaanyaIT_EXAM48_ManageQuestionBank.objects.get(QuestionID=request.POST.get(QuestionID, None))
        vbs.QuestionInEnglishLang = request.POST.get('QuestionInEnglishLang', None)
        vbs.save()
else:
        return render(request, 'exam48app/verifiedbysuperuser.html')

then what shoud the code of html page to view my all data to the tamplates..

this is my html page

<form class="from-horizontal" method="post"  enctype="multipart/form-data">
{% csrf_token %}
<div class="post-entry">
     {{ MaanyaIT_EXAM48_ManageQuestionBank.QuestionInEnglishLang }}
</div>
</form>

now what should i do?

pawas kr. singh
  • 416
  • 1
  • 4
  • 12

1 Answers1

1

From your comment, you need to know How to write/render the data from view to html template
I will demonstrate a simple example for you,
Assuming you have a view as below,

def VerifiedBySuperuser(request):
    if request.method == 'GET':
        context = {
            "T_Name": "My Name",
            "T_Age": 50,
            "T_Phone": 1478523699
        }
        return render(request, 'verifiedbysuperuser.html', context=context)


and a HTML template as follows,

<!DOCTYPE>
<html>
<body>
    Name : {{ T_Name }}<br>
    Age : {{ T_Age }}<br>
    Phone : {{ T_Phone }}<br>
</body>
</html>


When you access your view, you will get a response like this,

Output Image

In your case, you can pass as many attributes to template as dict (shown in my example) and in template/html keys of context (that is T_Name,T_Name etct) becomes variable. So you can directly use them in HTML inside the twin braces ({{ variable_name }})

As far as I knew, this is the general procedure for template rendering/ html rendering
UPDATE-1

def VerifiedBySuperuser(request):
    if request.method == 'POST':
        obj = MyModel.objects.get(id=some_id)
        other_data = [1,2,3,4,] # some specific data
        context = {
            "post_data": request.data,
            "object_instance": obj,
            "some_other_data": other_data
        }
        return render(request, 'verifiedbysuperuser.html', context=context)
JPG
  • 82,442
  • 19
  • 127
  • 206