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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:36:15+00:00 2026-06-02T09:36:15+00:00

I may have overcomplicated things. I have two views. The first view generates a

  • 0

I may have overcomplicated things.

I have two views. The first view generates a bunch of temporary data based on the user’s input from the form. Each of the generated data contains a name and misc data. I want to pass only the names to the template to be rendered as a list of hyperlinks. If the user clicks on one of them, the second view should be given the specific name the user clicked on so that the view can manipulate it. The only problem is, I don’t know how to get the misc data associated with the name.

The misc data generated could contain random characters that’s not a standard character in URLs, so I can’t turn misc into a hyperlink like I can with just the name.

I have something like this:
views:

# Displays the temp data names
def display(request):
    return render_to_response('display.html',{},context_instance=RequestContext(request))

# User provides input, generate temp data to be displayed as hyperlinks
def search(request):
    form = SearchForm(request.POST)
    if form.is_valid():
        usr_input = form.cleaned_data['input']
        data = generate_data(usr_input)   # generates a list of (name, misc) data.
        request.session['hyperlinks'] = get_list_names(data)   # returns only names in data
        return HttpResponseRedirect('views.display')

    else:
        ....

# User has clicked on a hyperlink, we must process specific data given its name.
def process_data(request, name):
    # How to get associated misc data created from search()?

I haven’t written the template yet, but the idea is:
template:

{% for name_link in request.session.hyperlinks %}
    <a href={% url process name_link %}> 
{% endfor %}

One solution could be creating a bunch of session variables:

for name in get_list_names(data):
    request.session[name] = // associated misc data

But this seems like a waste. Plus I’d have to manage deleting the session variable later on since this is only temporary data generated based on user input. A new input from the user would create another huge horde of session variables!

Another solution could be to store it temporarily in the database, but that also seems like a bad idea.

EDIT – Trying out suggestion by christophe31:
I’m not quite sure if I understand your suggestion, but is it something like this?

data_dict = {name1:misc1, name2:misc2, etc...}
encoded = urllib.urlencode(data_dict)   # encoded = 'name1=misc1&name2:misc2...etc'
request.session['hyperlinks'] = encoded

A few questions on this though:
1) Wouldn’t encoding it using urllib defeat the purpose of having a dictionary? It returns a string rather than a dictionary

2) To expand on (1), what if the misc data had ‘&’ and ‘=’ in it? It would screw up parsing which is the key and value by the second view. Also, misc data may have unusual characters, so allowing that to be part of the url to be displayed may be bad.

3) Does Django protect from allowing the user to maliciously modify the session misc data so that the misc data generated from the first view may be different than the one passed to the second view? That would be a problem!

  • 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-02T09:36:16+00:00Added an answer on June 2, 2026 at 9:36 am

    You may want to put a dictionary as a session variable, set a cookie, or pass as get argument throught the link your data.

    For me you have to put all these data in a dictionary before export it as get parameters (with urllib2) or store it in your user’s session.

    Ask me if you want more info on a suggested way.

    Edit:

    They are 2 ways I see, by session:

    data_dict = {name1:misc1, name2:misc2, etc...}
    request.session['hyperlinks'] = data_dict
    

    Or passing to the template the data if no session backend:

    data_dict = {name1:misc1, name2:misc2, etc...}
    encoded = urllib.urlencode(data_dict)
    return render(request, "my_template.html", {"url_params":encoded,}
    

    and

    <a href="{% url my_view %}?{{ url_params }}">Go to results</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may have to store some i18n-ed data in my database using XML if
I have a user condrol that may have several instances created and I am
I may have access to a search API that uses JSON based on a
You may have seen JavaScript sliders before: http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.slider.html What I'm envisioning is a circular
I may have my associations messed up. I have the following models: User and
You may have heard of PawSense , a Windows-only utility that prevents keystrokes from
This may have been answered before, and if so, point me to the answer.
I have a multidimensional points which may have keys of the following 3 types
As you may have guessed from the question - I am right at the
This question may have been asked before, but I had trouble finding an answer,

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.