Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

508
Views
Django how to open and display saved docx or pdf documents

I'm currently working on a question bank website using Django 1.87 that allow users o login and view saved past questions. so far i have been able to display links to the past questions in the database base on user selection. the past questions are uploaded as docs or PDF format and stored in the media directory.

I want logged in users to be able to open and read the content of the past question before deciding whether to print or download it. so far i have been able to display a list of links to the documents and when i click on a link it downloads the document to my computer. what i really want to achieve is for users to be able to click on a link and open the document from within the browser before clicking a download buttenter code hereon or print.

here are my codes:

models.py

class QuestionBank(models.Model):

date = models.DateField(_("Date"),default=date.today)
class_level = models.ForeignKey(ClassLevel)
course_name = models.CharField(max_length=350)
course_code = models.CharField(max_length=20)
question_papers = models.FileField(upload_to = 'Question_Papers/     %y/%m/%d')   

views.py def Questions(request, sel_course):

context = RequestContext(request)
SelCourse = sel_course.replace('_',' ')
context_dict = {'SelCourse':SelCourse}

try:
    Quest_For_course = QuestionBank.objects.filter(course_code = SelCourse)
    context_dict['Quest_For_course'] = Quest_For_course

except course_code.DoesNotExist:
    pass

return render_to_response('Qbank/QuestionsPage.html', context_dict, context)

in my Template i have this

QuestionsPage.html

<title> Question Papers </title> 

<body> 
    <h2> LIST OF QUESTION PAPERS FOR {{selCourse}} </h2>

    <h3> Select question to view, download or print it</h3>

    {% if Quest_For_course %}

    <ul>{% for ques in Quest_For_course %}

    <li><a href="{{ques.question_papers.url}}"> 

    {{ques.question_papers}} </a></li>

    {%endfor%}
    </ul>

    {%else%}
    <strong> THERE ARE NO AVAILABLE QUESTION FOR THIS CLASS AT THE MOMENT </strong>
    {%endif%}
</body>

how do i make past question documents view-able? on a form that has download and print button. thanks

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!