Answers for "retrieve object from context in django"

1

retrieve object from context in django

def index (request):
  context={}
  data= Data.objects.all()
  filesdata = 
  context["info"] = data 
  if request.method == 'POST':
    errorAndTime = addFile(request)
    context["error"] = errorAndTime["error"]
    context["time"] = errorAndTime["time"]
    # error = errorAndTime["error"]
    # time = errorAndTime["time"]
    return render(request, "dataAnalysis/index.html", context=context)
  #When you retrieve your data just call the name of the context u don't need 
  #to call it like this context.info or something like that 
      {% for data in info %}
            <tr>
              <td>{{ data.file_id }}</td>
              <td>{{ data.name }}</td>
              <td>{{ data.age }}</td>
              <td>{{ data.email }}</td>
              <td>{{ data.phone }}</td>
              <td>{{ data.gender }}</td>
            </tr>
      {% endfor %}
Posted by: Guest on March-12-2021
0

get context data django

class PublisherDetail(DetailView):

    model = Publisher

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super().get_context_data(**kwargs)
        # Add in a QuerySet of all the books
        context['book_list'] = Book.objects.all()
        return context
Posted by: Guest on July-09-2020

Code answers related to "retrieve object from context in django"

Python Answers by Framework

Browse Popular Code Answers by Language