retrieving a variable beyond the scope of a RequestHandler

I'm currently implementing a CSS3 accordion effect and I am concerned about potential security risks. Specifically, I want to prevent hackers from creating a script for parallel requests. For example, on my page I have both a login form and a registration form, but only one is visible at a time due to CSS3 rules that require the user agent to be HTML5 compatible. To address this, I am using the following technique:

class Register(tornado.web.RequestHandler): 
    def post(self): 
        tt = self.get_argument("_xsrf") + str(time.time()) 
        rtime = float(tt.replace(self.get_argument("_xsrf"), "")) 
        print rtime 
        
class LoginHandler(BaseHandler): 
    def post(self): 
        tt = self.get_argument("_xsrf") + str(time.time()) 
        ltime = float(tt.replace(self.get_argument("_xsrf"), "")) 
        print ltime 

I have utilized the _xsrf variable with unique values for each user in order to prevent the server from being tricked into thinking multiple requests are coming from the same machine. Now, my aim is to differentiate between the time values: abs(ltime - rtime). How can I access rtime outside of the class? I know how to retrieve the value outside of the method, but I need to perform this operation to identify if the value is small, indicating a potential scripted attack aiming to overload the server.

To illustrate with a simpler Python example:

class Product:
   def info(self):
       self.price = 1000
   def show(self):
       print self.price

car = Product()
car.info()
car.show()

Output: 1000

However, if I introduce another class like:

class User:
    pass

How can I create a method within this new class to print out self.price? My attempts using inheritance have resulted in an error (AttributeError: User instance has no attribute 'price'), suggesting that only methods can be passed down, not attributes.

Answer №1

If you're looking to grasp the concept of Model objects and patterns involving persistent data storage, it's important to understand that tornado.web.RequestHandler and its subclasses only exist within the duration of a single request cycle - from receiving the URL on the server to sending data back to the browser using methods like self.write() or self.finish().

To delve deeper into building MVC applications in Python, I recommend exploring tutorials on Django or Flask. Unfortunately, there are no specific Tutorials for this aspect when it comes to Tornado as far as I know.

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

"Short-term" variation not appearing within the Material-ui Drawer component

I am attempting to create a responsive drawer component using material-ui, where it is toggleable on smaller screens and remains open on desktop. Following the mui documentation, I added the temporary variant to the drawer, but it does not display in desk ...

The alignment of two elements is off in mobile display

Why aren't my two divs centered in mobile view? I am using Vuetify CSS flex helper justify-center to try and achieve it, but it doesn't seem to be working. Even when I use justify-sm-center, it still doesn't work. What am I missing? <v-co ...

Angular 2 failing to show "mandatory" dialogue on the form

I am new to Angular 2 and have created a form using Angular 2 and bootstrap. When I click on the text field and then move the mouse elsewhere, the box turns red, which is working correctly. However, when I click on the submit button with an empty form, it ...

Is there a way to show a fallback message for unsupported video file formats?

When incorporating a video element on my webpage, I typically use the following code: <video src="some source" controls> Error message </video> Based on my knowledge, the "Error message" will only appear if the browser does not support the ...

What is the solution to eliminating the MultiValueDictKey error when making an AJAX get request?

When handling multiple divs on a web page, each containing a form, I encountered the need to utilize AJAX Get functionality. The goal was to pass the text entered into a form along with the ID of the corresponding div to a Django view for storage in a data ...

How to Programmatically Assign Bootstrap Class to an Element Using Angular 2

I am working on a page with several input boxes that need to be flagged for certain criteria. <div class="form-group"> <label class="d-block">Allowance Type</label> <div class="input-group"> ...

How wide can we make the Outerbounds in the Chrome app?

My setup includes a chrome box that can accommodate two monitors. I am interested in creating a single chrome app with dimensions of 3840x1080 (width =3840, height =1080) to cover both screens. I attempted this but was unsuccessful. Are there any alterna ...

The various sections of my website are neatly tucked away under one tab, only revealing themselves to users as they click on each individual tab

My recently published website is experiencing a strange issue. When the site loads, all contents including paragraphs and videos from other pages are displayed under one tab (the HOME tab). However, once any other tab is clicked, the issue fixes itself. Yo ...

Can a complete form be encapsulated within a single AngularJS directive?

While I have come across several instances of individuals utilizing a blend of HTML and directives to craft an AngularJS form (as seen here), my goal is to develop a self-contained widget. This widget would encompass all the necessary HTML for the form w ...

How to handle @use imports from node_modules when using the sass node CLI?

Exploring the capabilities of SASS through material web components has been quite intriguing. To begin, I initiated a new node project in the following manner: mkdir sassplayground Then, I installed the necessary dependencies: cd sassplayground npm i @ma ...

Is there a way to programmatically access a hyperlink in Python using Selenium?

I am currently learning Python and Selenium, and I need help scraping a page for specific HTML elements. Here is an example snippet of the page I am working with: here. I am looking to scrape data based on the data-attr1 attribute provided in the HTML s ...

Can Webpack be used to produce only CSS files without generating the output.js file?

I've integrated Webpack into my project alongside the extract-text-webpack-plugin. Within my project, I have various build scripts. One of these scripts focuses solely on bundling and minifying CSS. While utilizing Webpack for other tasks, I decided ...

Tips for effectively utilizing radio buttons to obtain the chosen value

I am looking to retrieve the value of the selected radio button to use in JavaScript, then display it on an HTML page. Here is the Javascript code: $scope.bases = [{ name:'Tomato', price:3 },{ name:'Cream', ...

What is the best way to ensure a logo image is properly scaled to fit its parent container using Bootstrap 4

I am struggling with my navigation bar, which consists of a simple logo and a few links. The issue I am facing is that the logo image is too tall for the parent container, which has a fixed height. It's clear that the logo with the gray background e ...

Is it possible to customize the appearance of ordered list numbers using javascript?

Is it possible to change the color of a specific line number in an ordered list using JavaScript? I am familiar with CSS styling such as li::marker, but curious about altering individual list item markers dynamically through JavaScript. How can this be ach ...

Tips for designing a sleek and seamless floating button

I attempted to implement a floating button feature that remains in view while smoothly flowing using jQuery. I followed a tutorial I found online to create this for my website. The tutorial can be accessed at this link. However, after following all the ste ...

Tips for swapping out a JavaScript variable for a JSON file

I'm currently in the process of developing a website and I'm relatively new to website coding. My aim is to have a rotating text feature that switches between words, similar to a splash text seen in games like Minecraft. I understand that it woul ...

create a division in the organization of the identification numbers

Is there a way to always change pages when the id changes in a foreach loop to separate the printed pages? Take a look at this code snippet: var data = [ {Id: "552", valor: "50.00", Descricao: "Fraldas", }, {Id: "552", valor: "35.00", Descrica ...

If the width of the window is greater than 1080, do this action. Otherwise, switch back to using CSS and ensure to check for changes upon

I am creating a section on a webpage where the height is determined by screen.availHeight. It works perfectly, but I also want it to reset to the default height in the CSS when the width goes below 1080px. I've tried different approaches, but haven&ap ...

When I include a class in a checkbox label, the CSS ceases to function properly

Apologies for my lack of understanding, but I am facing an issue with applying an attribute to a label element with class "c". It seems to work fine with other objects, like buttons, but not with labels. I cannot figure out why such a simple thing is not w ...