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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:50:02+00:00 2026-06-10T03:50:02+00:00

My question involves passing variables from the template to view in Django. I know

  • 0

My question involves passing variables from the template to view in Django.

I know of passing variables in the URL and through a form. The problem I have with the first one is that the url could be manipulated which is not what I want. Is there anyway to prevent that?

Right now this is what I have as a band-aid:

<form action="/match/" method="post">
{% csrf_token %}

<input type="hidden" name="name1" value="{{ male_results }}">
<input type="hidden" name="userid1" value="{{ male_pic_userid }}">

<input type="hidden" name="name2" value="{{ female_results }}">
<input type="hidden" name="userid2" value="{{ female_pic_userid }}">

<input type="submit" value="Submit" />
</form> 

Is there a way to avoid having to use this? Thank you!

  • 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-10T03:50:04+00:00Added an answer on June 10, 2026 at 3:50 am

    There are broadly 3 ways to hold onto this kind of information:

    Session (my suggestion for your situation)

    Just stuff the data you want into the request.session dictionary; it’ll persist per-user, and you can access it easily:

    # view1
    request.session['name1'] = male_results
    request.session['userid1'] = male_pic_userid
    
    # view2 (or elsewhere in view1)
    male_results = request.session.get('name1')
    male_pic_userid = request.session.get('userid1')
    

    Advantages

    • No changes needed to your templates (except removing your now-unnecessary forms).
    • Clean URLs
    • Persists even through closing and re-opening the browser window
    • You don’t need to worry about users modifying or even seeing the session data (it’s way more secure)

    Disadvantages

    • As with POST, page content is dictated by the URL and session data — URLs are no longer unique, and users can’t share a particular page that relies on session info

    Query parameters

    Something like /match/?name1=foo1&userid1&name2=bar&userid2=2. You can either add these manually (<a href='/match/?name1={{ male_results }}...) or by changing your POST form to GET.

    Advantages

    • These URLs can be shared and bookmarked; if it’s a list with filtering options, this is probably desirable (“Here’s the list of cars I like” posted to Facebook, etc.)

    Disadvantages

    • As you’ve already noted, these can be freely modified by the user
    • Adding these to every URL is a massive pain

    POST form (your current approach)

    Advantages

    • A little more hidden (nothing user-visible without some kind of browser extension)
    • Slightly harder to manipulate (though don’t rely on this security-through-obscurity)
    • Cleaner URLs

    Disdvantages

    • Leads to “this page has expired” messages on Internet Explorer if you use your browser’s “back” button …
    • … and “Are you sure you want to re-send this data” messages on most browsers if users try to reload any of your pages
    • All this state information will be lost if a user re-opens the page (pressing “return” in the URL bar, for instance)
    • Users can’t share the exact page they’re looking at; the content is partly determined by non-user-visible information
    • Adding POST data to every navigation action is a huge pain.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding passing a variable that is a char array from
This question involves 3 tables and 1 form in my Access database. The tables
I have a question which involves calling a function with 2 parameters of a
I have a question which I think involves conditional entropy in the field of
My question is regarding i18n in Python. From what I understand, it involves: Create
I have a question about doing a query through a few associations using Ruby
I'm following on from a previous question . The answer I accepted involves using
My question involves this simple walkthrough shown in the article Preserve Size and Location
This is more a general question but my particular case involves a ruby/rails app
This is mostly a data warehouse philosophy question. My project involves an Oracle forms

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.