title: How can I view the pdf file in Django?
body: <p><strong>Note:</strong></p>
  
  <ol>
  <li>My model table consists of id field and File field which will be pdf.</li>
  <li>I am inserting data into the model using django admin.(I have no custom upload form)</li>
  <li>I am trying to view the pdf in the browser(as it normally opens in chrome).</li>
  <li>I am trying to find the file by taking the id field(by user) in a custom HTML template using a form(Please look at the codes mentioned below.)</li>
  <li>I am attaching the urls.py, index.html, views.py, models.py and forms.py codes below. Please patiently go through and let me the know the problem and the solution. </li>
  <li>I think my code should work but I am getting a Suspicious File Operation Error.</li>
  </ol>
  
  <p><strong>urls.py</strong> </p>
  
  <pre><code>urlpatterns = [
      path('',views.index),
      path('admin/', admin.site.urls),
  ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p><strong>views.py</strong> </p>
  
  <pre><code>def index(request):
      if request.method == "POST":
          form = Form(request.POST)
          if form.is_valid():
              id=request.POST.get("id")
              ans = query.objects.get(id=id)
              response=ans.repo
              if ans is None:
                  return redirect("index.html")
              else:
                  #return render (request,"ans.html",{'ans':response})
                  return redirect(response)
      else:
          form = Form()
      return render(request,"index.html",{'form':form})
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class Form(forms.Form):
      id = forms.CharField(label="Report ID", max_length=100)
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class query(models.Model):
      id=models.IntegerField(primary_key=True)
      repo=models.FileField(upload_to='documents/')
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!-- Search Form --&gt;
          &lt;form id="signup-form" method="POST" action=""&gt;
          {% csrf_token %}
              {{form}}
              &lt;input type="submit" value="Check" /&gt;
          &lt;/form&gt;
  </code></pre>