The saving of data in the session is not working as expected

Currently, I am in the process of building a web application with Google App Engine and Python. I have encountered an unusual issue that has left me stumped on how to resolve it and what might be causing it. The problem arises when I fill out a form and send the data for validation. If any fields are incomplete or missing, the server sends back the form with a prompt saying "FILL ALL THE FIELDS!"

This functionality works quite well.

My objective is to return the form with the "description" and "title" fields pre-filled with the user's previous input before submitting the form. This way, the user would only need to complete the unfilled fields without having to re-enter everything from scratch.

Here is the snippet of the code:

class SaleAnnCheck(BaseHandler):
  # Python code implementation goes here

class Create(BaseHandler):
  # More Python code implementation goes here

Upon form submission, the content undergoes checking through an HTTP post request to a specific URL managed by SaleAnnCheck.

The session accurately stores the Description and Title values (verified via the logs). However, if a field is left blank, the server redirects back to the form page through a GET request to a related URL.

The requests to this URL are handled by Create. Strangely, when attempting to render the HTML template of the form using jinja2 with the previously entered Description and Title values, the corresponding text areas remain empty. This discrepancy occurs despite verifying non-empty values earlier in SaleAnnCheck.

I am puzzled as to why this happens. Can anyone shed light on this peculiar issue? Thus far, I have been unable to find any insights or recommendations online.

Answer №1

The reason for this issue is that 'self.session' in not an instance of Session, rather it's a class variable and therefore cannot be accessed from outside the class. If you are looking to utilize persistent sessions for storing variables, consider implementing something like the following:

As stated in the documentation: http://docs.python-requests.org/en/master/user/advanced/


s = requests.Session()

s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get('http://httpbin.org/cookies') 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Scrolled region in Python tkinter canvas not responding to events

I am currently developing a Python program using Tkinter GUI and the canvas element. I have implemented a scrollbar on the canvas to allow users to navigate unseen areas of the canvas. A dotted grid has been created where users can hover over dots and clic ...

Encode JavaScript field without affecting the appearance

I need to encode a specific search field before submitting it as a $_GET request. To do this, I am using the encodeURIComponent() function on that field before the form is submitted. $('#frmMainSearch').submit(function() { var field = $(this ...

How does the count method function in Python when there is no string provided?

I have a question about why Python is returning the answer as 7 even though there is no string specified in the count method. txt = "banana" x = txt.count("") print(x) ...

Creating a unique Deterministic or Stochastic model in pymc3 using theano.op: A step-by-step guide

Currently working with pymc3 and interested in creating custom Stochastics. However, I'm finding limited documentation on how to accomplish this task. While I am familiar with using the as_op method, it appears that doing so renders the NUTS sampler i ...

Using Django to execute queries that are not tied to a specific database technology

Initially, I am aware that my question may seem similar to this question, but I believe it has unique aspects. I am looking for a way to store user "search filters". From what I understand, Django ORM generates SQL queries specific to the database being u ...

Retrieve all functions invoked within a Python code snippet

Having a package and a script that calls the functions in the package presents some challenges. The package is quite extensive, serving multiple purposes, and I am looking to extract only the necessary functions for a specific script. My query is this: ca ...

Logging in Python: A Guide to JSON Formatting

Our Python Django application requires logging using the code snippet below in order to allow ELK to index the log record as JSON logger.info(json.dumps({'level':'INFO','data':'some random data'}) We currently have ...

Python allows for the retrieval of the aria-label attribute as text based on the div id with the help of libraries like Beautiful Soup

<div id="i19" class="quantumWizTogglePapercheckboxEl appsMaterialWizTogglePapercheckboxCheckbox docssharedWizToggleLabeledControl freebirdThemedCheckbox freebirdThemedCheckboxDarkerDisabled freebirdMaterialWidgetsToggleLabeledCheckbox isC ...

What's causing the xpath's at thepiratebay3.org not to function properly?

Having trouble getting selenium to click on a link for me as it can't find any xpaths, and I'm unsure why Here's the code: from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.chrome.options import Option ...

How come the statement (1 in [1,0] == True) results in False?

In my search for answers on this particular question, I stumbled upon a confusing discovery regarding my own response. I am puzzled by the parsing of this situation. Why does the outcome from the second example come back as False? >>> 1 in [1,0] ...

Having trouble retrieving req.session variables in Express/NodeJS?

I have come across various versions of this particular question, however, none of them seem to address my issue directly. My current objective is to establish a Node.js server using Express. Below is my existing server configuration: var express = require ...

Using the react-form library to create nested components with react.cloneElement

There is an issue that needs fixing with the library called react-form. Here is the error message I am currently facing: Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) ...

I am curious if there is a specific Python function that can help pinpoint the exact location of the purple circle on the screen

I need help pinpointing the location of the purple circle and encountering similar scenarios in various datasets where there is a noticeable horizontal delay before the sensor begins collecting data. Any suggestions or insights? https://i.stack.imgur.com ...

Leverage the power of Express.js to efficiently retrieve data from a MongoDB data store

I'm in the process of developing an e-commerce website where I store all the data in a database as well as a session store. For logged-in users, only the login credentials are stored in the session store. However, I'm facing an issue when it come ...

Combining two CSV files based on a shared column using Python

My current challenge involves merging two csv files that share a common id column and then saving the merged data to a new file. I attempted to do this using the code snippet below, but encountered an error: import csv from collections import OrderedDict ...

Can you explain the distinction between chromedriver_binary and chomedriver.exe when using selenium with Python?

Based on my understanding, there are two approaches to utilizing a chrome driver with selenium in python: The first method involves downloading the chromedriver.exe file and then integrating it into the parameters like so: browser = webdriver.Chrome(exe ...

tensorflow-addon is not designed to be compatible with the previous versions of tensorflow, specifically

Currently, I am dealing with code that utilizes TensorFlow 1.14 along with tensorflow-addons. However, it appears that the available versions of tensorflow-addons for installation are only compatible with tensorflow >= 2. When attempting to install an ol ...

What is the most efficient way to create a large grid of entries using Tkinter?

I'm looking to challenge myself by creating a Sudoku solver using tkinter, but I'm stuck on how to create the grid for users to input the sudoku board. My initial thought was to use Entries for each cell, but that would mean creating 81 of them ( ...

I am struggling to make the map method display the specific components I need

Attempting to create a scalable Custom Form using an array of objects and a custom Input field in a React-Typescript project import React, { ChangeEvent } from "react" import { InputField } from "./InputField" interface FormItem { ...

What is the best way to parameterize the copy command for the Kubernetes API using Python?

I'm currently working on a project that involves creating a duplicate of a file within a Kubernetes container using the Python API. Here is the function I am planning to implement: def make_file_duplicate(self, file_name, pod_name, pod_namespace=Non ...