I would like to know if it is possible to submit a flash form from python and, if it is, how?
I have done form submitting from python before, but the forms were HTML not flash. I really have no idea on how to do this. In my research about this I kept getting 'Ming'. However, Ming is only to create .swf files and that's not what I intend to do.
Any help on this is greatly appreciated.
You can set the url attribute (I think it's url, please correct me if I'm wrong) on a Flash form control to a Python script - then it will pass it through HTTP POST like any normal HTML form.
You've got nothing to be afraid of, it uses the same protocol to communicate, it's just a different submission process.
For your flash app, there's no difference if the backend is python, php or anything, so you can follow a normal "php + flash contact form" guide and then build the backend using django or any other python web framework, receive the information from the http request (GET or POST, probably the last one) and do whatever you wanted to do with them.
Notice the response from python to flash works the same as with php, it's just http content, so you can use XML or even better, JSON.
Related
Goal: I want to send the result of a <script> tag in HTML to a server of any kind.
I am working with the Spotify authorization API for a project and one of the required keys is contained in a query string at the end of my app’s redirect URI. I need to get this key.
My solution is to set the redirect URI to a redirect page. Then, on the page, automatically run a script that gets the current URL and send it to my Python script for use. If there’s another way, please tell me, because I’m pretty stuck.
However, to send variables between HTML and Python, I have found I need to use a simple server. Setting this up is the hard part. I’ve made Java, Node.js, and Python servers, but nothing seems to want to work with the <string> tag, and I’m doubtful something like this would even get the actual output of the script.
Is there a way to do this? This is a pretty long question and I apologize, and it should probably be noted I’m a beginner so an explanation and code examples would be nice. Thank you to anyone who reads this!
So I am attempting to use bottle.py and twitter bootstrap together to make a small website. I need to be able to insert a reasonable amount of data at various points in the HTML using Python but I am not really sure I understand how the HTML and python are communicating.
Here is an example of twitter and bottle working together.
He mentions linking a couple of .js files in the html and I can see where he does that but I am not really sure how that affects how the python interacts with the html. Is there a callback from the Javascript that the python catches using request.GET.get().strip():?
Also one of the last lines is:
return template('templates/gpio.tpl', colour1=colour1, colour2=colour2, colour3=colour3)
I am not sure how the templates/gpio.tpl is connected to the html he mentions below. I understand that the colour# variables are referenced in the html (I assume this happens with the {{}} syntax) but I am not sure how the html gets called at all.
From what I understand (which so far isnt a whole lot) this is how it goes:
User enters "server:port/gpio" into a webbrowser
The python decorator gets called by bottle and the function is run returning the template at the bottom.
This is where I get confused.
A) How does the python script know to call the html?
B) How does the gpio.tpl template code get sent to the html?
C) Is it safe to assume that the python arguements sent to the template function can be referenced using the {{}} syntax or is there more to it?
D) How does the html call back to the python to update the buttons he shows at the bottom?
D.1) does the JS linked at the top have something to do with this?
Lastly: If anyone has a another/better example of linking bootstrap and bottle I would be very happy to see it.
This is quite a loaded post. Thank you for your patience. :D
You'd really need to first learn how the HTTP protocol works... But let's try to quickly answer your main question:
how the HTML and python are communicating
Quite simply: they don't. What happens is:
your client (usually your browser) send an HTTP request to your site
the front web server (Apache, Nginx, whatever) sends this request to the bottle.py application
the bottle.py app dispatch the request to the right controller function matching the url's path portion and request's method against the defined routes)
the controller function does what it has to do and returns an HTTP response to the front web server
the front web server send this response to your client
Usually - but not necessarily - the HTTP response contains HTML content, generated by the controller using a template. IOW : bottle.py uses the template to generate html that is sent back to the client.
Once the response is sent, there's no more "communication" until the client sends another request.
So if I wanted to make an html button that changed something on the page how would I send that response back to bottle.py regenerate the page with the change?
It depends on what you want to change...
For example, pushing the button could trigger a new HTTP request, you should then define a new feature in your code.
Let's take the previous example, and imagine you want to add a switchOff button.
You have to add the following button somewhere in the gpio.tpl :
<input type="submit" class="btn" name="LedsOff" value="Turn off the leds!">
Then, modify the function gpio() to add a new condition with the following :
elif request.GET.get('LedsOff','').strip():
from quick2wire.gpio import Pin, exported
with exported(Pin(12, Pin.Out)) as out1, exported(Pin(13, Pin.Out)) as out2:
out1.value = 0
out2.value = 0
I am currently pulling data from a public series data from https://www3.bcb.gov.br/expectativas/publico/en/serieestatisticas
This is a public page that uses apache wicket I believe.
I usually am ok with scraping, whether GET or POST. Here I and my colleagues are stuck. Can anyone help understand what URL needs to be used to actually make the request. Here's what I've got so far:
The form with inputs:
The Fiddler capture manually executed:
Text View:
form19_hf_0=&indicador=0&calculo=0&linhaPeriodicidade%3Aperiodicidade=0&tfDataInicial=11%2F10%2F2015&tfDataFinal=11%2F24%2F2015&divPeriodoRefereEstatisticas%3AgrupoAnoReferencia%3AanoReferenciaInicial=16&divPeriodoRefereEstatisticas%3AgrupoAnoReferencia%3AanoReferenciaFinal=16&btnCSV=Generate+CSV
Form data I'm passing in the request:
Summary:
I need some help, I can't seem to get the POST working correctly, it takes me to a different page, and I'm not sure of how to work through this one.
NB: I'm trying to grab back a CSV.
The libraries I'm using are primarily Requests (I was going to use LXML but I don't think its going to be applicable here).
I've been trying to figure out the right form with Postman and Fiddler to understand what the request needs to be.
So,
The solution to this was somewhat indirect. We were not able to do a straight POST because the the page incremented the actual POST url in a way that was generally impossible to predict.
The solution that we used was installing Selenium web driver and using that to simulate the dropdown visible values and button clicks.
This worked out very cleanly.
Thanks and HTH anyone else who might have a similar problem.
I need to develop a simple login page using Python language with two fields and a button, like:
Username, Password, Login
I know there are some beautiful Python frameworks like
Django, Grok, WebPy, TurboGears
which support web development using Python, but mine is a basic requirement consisting of only 3 screens (pages):
1st page - Login page (Redirects to 2nd page when login button is clicked)
2nd page - Page with records in the form of a list, with an option for adding new records (Redirects to 3rd page when "Add Records" button is clicked)
3rd page - Page with fields, which are saved as records for the list on 2nd page (After entering details and clicking Submit)
So, I have decided to develop the above functionality using Python without using any framework, so that I can have flexibility as well as write my own code.
Is it possible to create a login page using Python without using a framework?
I haven't worked on web services and don't know the basics of web development in Python.
If possible, can you provide me an example on how to create a login page using Python and achieve the functionality described above?
Firstly, it's good to learn how to do things without the frameworks, but if you're doing this for anything but educational purposes it's most likely a mistake to say "my requirements are too simple to bother with frameworks." What you describe is on the simpler end of the spectrum, but already I can see some complications you're probably glossing over.
Anyway, to implement your 3 pages, you will need:
a web server
2 static HTML files
python handlers for GET on 2nd Page, POST from 1st and 3rd Page
storage (either flat file or database)
Look at A Simple Python CGI Server Tutorial to get started, and there are more details at TutorialsPoint: Python - CGI Programming.
Your HTML forms just need to have method="POST" and action set to the URL you're serving from python for each form. Your POST handlers should do what they need to do and then serve a 302 redirect.
If you don't know the basics of python web development, you're going to have your hands full and should probably start with a single user flat-file system. Maybe you can even get away with storing that in memory for now. Then if/when that stops doing it for you, try sqlite. Configuring web servers is a pain, too, so if you can just stick with BaseHTTPServer.
Finally, load your records in another python endpoint, make some HTML for each, slap it in a big string with surrounding HTML, and serve that puppy.
You requirement is very trivial. Though people may suggest micro frameworks like flask, bottle I would say you should try Django and have a look at Django Admin Panel. I think it's possible for you to meet your requirement using the Django admin feature.
Updated
Have a look at this http://docs.python.org/howto/webservers.html
Without a framework and if you don't want to mess with CGI you can take a look at http://webob.org/ .
Am new to Django but want to learn it and have covered pretty much the basics on the Django website.
Here is my problem:
I have written a python script which presently works in the python shell, but I want to make use of the script on my web. So that when a user goes to my website and provides the neccesary input, clicks submit, the webpage links the input to the python script(which already has input fields like those on the webpage), and the python script runs according to the input given by the user, evaluates it and prints the result of the script on the webpage.
Please help me out guys, counting on you all.
But feel free to suggest other frameworks that could best serve my problem.
It sounds like you would be better off moving the contents of your script into a django view and executing it after your form has been validated.
https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs#using-a-form-in-a-view
In your view, you can get the form data using request object. You can pass the form values to your script and send output to your response object.
It seems you didn't completely understand how django works. Please go through the tutorial again.