Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:22:40+00:00 2026-06-11T11:22:40+00:00

I am new to Django and HTML and I am trying to display a

  • 0

I am new to Django and HTML and I am trying to display a list of data derived from a form on the HttpResponseRedirect page. I have been reading Django APIs but I am still unsure of how to use HttpResponse() and HttpResponseRedirect().

As of now I understand that response = HttpResponse() makes an HttpResponse object of and HttpResponseRedirect(‘results’) redirects the browser to a new html template page.
What I dont know is how to write results.html to display on my browser.

I need help on how to write the HTML page.

I also need help on how to pass a list of data to that html page.

I would also be ok with displaying the list on the same html page the form is in instead of loading a new page.

Current code:
def contact(request):

if request.method == 'POST': # If the form has been submitted...
    form = ContactForm(request.POST) # A form bound to the POST data
    chosen = []
    if form.is_valid():
        strt = time.time()
        form = form.cleaned_data
        parameters = organize(form)
        print 'input organized'
        chosen, companies = multiple(parameters)
        end = time.time()
        pp.pprint(companies)
        print 'companies matching search filters: ' , len(companies)

        print 'total time: ' , str(end-strt)



    response = HttpResponse(chosen)
    return HttpResponseRedirect('results') # Redirect after POST
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:22:41+00:00Added an answer on June 11, 2026 at 11:22 am

    I think what you want is Django’s render_to_response shortcut. The first argument is an html template to use, and the second is a dictionary of values to pass to that template.

    At the top of your views.py file, include:

    from django.shortcuts import render_to_response
    

    and modify your code to read:

    if request.method == 'POST': # If the form has been submitted...
        form = ContactForm(request.POST) # A form bound to the POST data
        chosen = []
        if form.is_valid():
            strt = time.time()
            form = form.cleaned_data
            parameters = organize(form)
            print 'input organized'
            chosen, companies = multiple(parameters)
            end = time.time()
            pp.pprint(companies)
            print 'companies matching search filters: ' , len(companies)
            print 'total time: ' , str(end-strt)
        return render_to_response('results.html', {'chosen':chosen,'companies':companies,'start':start,'end':end}) # Redirect after POST
    

    Note that the second argument is a dictionary of values you’d like to pass to your template. The way I’ve written it, you’re passing 4 values (chosen, companies, start, end) but you can include as many as you’d like.

    Then create a file named results.html in your Templates directory (which is specified in the TEMPLATE_DIRS variable in your settings.py file). It could look something like this:

    <!DOCTYPE html>
    <body>
    <h1>Results</h1>
    <p>Chosen: {{chosen}}</p>
    <p>Companies: {{companies}}</p>
    <p>Start: {{start}}</p>
    <p>End: {{end}}</p>
    </body>
    

    Django template syntax uses double curly braces {{}} to display variables passed to the template.

    Note that this approach will not change the URL. If you need to do this, try looking at this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDITED I'm trying to use jquery/ajax to display data returned from a django method.
I'm new to Django (and Python) and I have been trying to work out
I'm trying to make a signup form via html/django so I have 3 input
I'm new to django and I'm trying to get display a list of buildings
I'm new to Django and Python, and have spent a couple days trying to
I am new to django, and have been tying to pass a User object
I'am trying to display data from the database file which has the value Age
I'm new to django, I'm trying to figure out how to include other html
i'm new to django and im trying add a user using django admin page.
In Django, I have been trying to get a search field to geocode a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.