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 6919619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:00:50+00:00 2026-05-27T10:00:50+00:00

I use a form in template,and I want to redirect a friendly url when

  • 0

I use a form in template,and I want to redirect a friendly url when user fill the form
I search many issue in stackoverflow,I think my problem like this issue: Django form redirect,
but I can’t understand the template tag,so I can’t solve my problem.

I write the form:

<form  method="GET" action="/stock/search">
  search:<input class="search" name="search" type="text" value="" id="serach" >
  <input type="submit" value="Go"/>
</form>

and write the urls:

url(r'^(?P<number>\w+)/$', 'stock.views.stocknumber'),
url(r'^search/$', 'stock.views.search'),

and the views:

def stocknumber(request, number):
    """
    stock info
    """
    stock = Stock.objects.filter(number="%s"%number)
    stock_number = Stock.objects.filter(number="%s"%number)
    stock_reportinfo = Reportinfo.objects.filter(number="%s"%number)
    stock_blockinfo = Blockinfo.objects.filter(number="%s"%number)
    stock_stockinfo = Stockinfo.objects.filter(number="%s"%number)
    data = Stockhq.objects.filter(number="%s"%number).values('timeStamps','openData','highData','lowData', 'closeData', 'volData').reverse()
    datalist=[ ]
    for item in data:
        d =[item['timeStamps'].toordinal(),item['openData'],item['highData'],item['lowData'],item['closeData'],item['volData']]       
        datalist.append(d)

    hisdata = datalist

    return render_to_response(
        'stock/stock.html', 
        {"stock_number": stock_number,
         "stock_reportinfo": stock_reportinfo,
         "stock_blockinfo": stock_blockinfo,
         "stock_stockinfo": stock_stockinfo,
         "hisdata":simplejson.dumps(hisdata) ,
        }, 
        context_instance=RequestContext(request))

def search(request):
        return HttpResponseRedirect('/stock/%s/'%request.GET['search'])

and now I hope the user input the stock number and redriect to the friendly url like:http://&#8230;./stock/YHOO
and this url is get the stock info to render template,is this idea is right?

if it is ,what is the correct code ?

  • 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-05-27T10:00:51+00:00Added an answer on May 27, 2026 at 10:00 am

    I don’t think that question is really similar to your question, if I’m understanding correctly. Because that one already predetermines the action of the form, the redirected URL doesn’t seem to depend on the user input. So I’m not entirely sure what your question is.

    Are you implementing a simple search that, when a user inputs the stock’s number (I’m assuming you consider “YHOO” a number? Is the “number” input something like “YHOO” or is it actually a number?), the stock with the number (so “YHOO” stock) is displayed with all of its information on a new page with the URL “http://…/stock/YHOO”?

    In any case, here are some observations.

    stock = Stock.objects.filter(number="%s"%number)
    stock_number = Stock.objects.filter(number="%s"%number)
    

    Is there a reason why you have both when you don’t use the first one? In addition, are numbers unique? If so, you can just do Stock.objects.get(number=number), because:

    1. You would use “get” instead of “filter” because you’d expect a
      single record to match that.
    2. Number is already a string when
      passed in, so you don’t need to do “%s” % number.

    You can also try the following instead of using the actual URL, to make it more Django-like.

    from django.core.urlresolvers import reverse
    ...
    def search(request):
        number = request.GET['search']
        return HttpResponseRedirect(reverse('stock.views.stocknumber', args=(number,)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to redirect my form after submissions, I'm trying to use a hook,
I want to re-use a template I have with my WTForms form: <th>${form.name.label}</th> <td>${form.name()}</td>
I want to use a dynamic ui:include, like this. <ui:repeat value=#{FormsService.getTemplates(component.form)} var=template> <ui:include src=forms/#{template.id}.xhtml/>
I need to insert the comment form directly to the node template (I use
I have an express app that I want to use the connect-form module on
I am trying to use form validation for my form after user submits it.
I use an MVC template to allow the user to add multiple addresses. They
I want to use this pure HTML/CSS template for my ASP.NET website: http://sub3.tanguay.de I
For rendering form errors in a twig template, you just have to use the
I have a template page expecting two forms. If I just use one form,

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.