top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Application Context and Request Context in Flask and WerkZeug.

+2 votes
806 views

I am developing a web application using flask, Werkzeug and jinja2. I am very much confused with these terms and wanted to know the meaning of the terms and how they are interrelated to the CGI environment variables. What is global variable g and how it is related to the application context and request context.

Also since I don't have much knowledge of developing web apps( I am doing it for first time) any another language also so there is another request if someone could give a reference or make me understand that how the requests are handled, i mean what happens when a request arrives to the web application.
Also if i am not using any openID providers for logging in the user into my website, how can i make the password secure. Should i use any framework for that?

posted Apr 7, 2014 by Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Django will probably be a better bet for you. Especially as it comes with an authentication app that deals with storing passwords etc

2 Answers

+2 votes

The best I can suggest is that you start learning to write ordinary Python programs before you embark on writing web programs with those libraries or frameworks. The best place to start is here:

https://wiki.python.org/moin/BeginnersGuide

If you're beyond that stage, you might find this page useful:

https://wiki.python.org/moin/WebApplications

answer Apr 7, 2014 by anonymous
+2 votes

Please look at this link What is the purpose of Flask's context stacks? Better spend a little time to understand it because it basic framework principal.

Many approaches for user data storing will be secure, the easiest store user in database and password as modern_crypto_hash(password + salt) with limitation for short passwords acceptance and use something for logging as Flask-Login or Flask-Principal. To avoid SQL injections you can use any ORM, for example SqlAlchemy. To avoid XSS send data changing by POST and add csrf token, WTForms good there. To avoid html tags injection already use build in template system by default and do not insert user content to page unsafely. Also can be useful https.

answer Apr 9, 2014 by anonymous
Similar Questions
+1 vote

I would like to create a web app using flask or cgi library (python) along with telnetlib to telnet to specific servers and execute commands and retrieve the output. The output will then be formatted and outputted to a webpage .

Is this the best way of getting info from a remote system to be output to a web page? Is flask over kill for project like this ?

0 votes

i want to sent a response for my form submit from server to client, that means python flask to javascript. My javascript code is given follows

document.addEventListener('DOMContentLoaded', function() {

chrome.tabs.getSelected(null, function(tab) {
  d = document;
  var f = d.createElement('form');
  f.action = 'http://127.0.0.1:5000/Get%20Form/';
  f.method = 'post';
  var i = d.createElement('input');
  i.type = 'hidden';
  i.name = 'url';
  i.value = tab.url;
  f.appendChild(i);
  d.body.appendChild(f);
  f.submit();   
});
$(".button").click(function(){
    request = new XMLHttpRequest();
    request.open("POST","http://127.0.0.1:5000/PutValue/",true);
    request.send();
    request.addEventListener("readystatechange", processRequest,false);
    function processRequest(e)
    {
    if(request.readyState==4 && request.status == 200)
    {
    var response = JSON.parse(request.responseText);
    a=response.result
    alert(a);
    }
    }
});
},false);

And my Python server code is follows

from flask import Flask, flash, redirect, url_for, request, render_template,jsonify
import json
import UrlTest
import trainingSet as ts

app = Flask(__name__)
user=""
s=0

@app.route('/Get Form/',methods = ['POST'])
def GetForm():
request.method == 'POST'
url=request.form['url']
UrlTest.process_test_url(url,'test_features.csv')
s=ts.main_caller('url_features.csv','test_features.csv')
print s
return str(s)

@app.route('/PutValue/',methods = ['POST'])
def PutValue():
request.method == 'POST'
print s
return jsonify(result=s)


if (__name__ == '__main__'):
app.run(debug=True,host='0.0.0.0', use_reloader=False)

I want to send the value of s to the javascript client. please help me to send this the value of s.
and if u can suggest the complete code in javascipt and python

+2 votes

I have a python web application running on apache2 deployed with mod_wsgi. The application has a thread continuously running. This thread is a ZeroMQ thread and listening to a port in loop. The application is not maintaining session. Now if I open the browser and sends a request to the apache server the data is accepted for the first time. Now when second time I send the request It shows Internal server error. When I checked the error log file for traceback, It shows the ZMQError:- The address already in use.

Does apache reloads the application on each request sent from the browser since so that the ZeroMQ thread is being created everytime and being assigned the port but since the port has already been assigned it shows error....

...