Python - Retrieving data from web server - python

I am making a program where I need to get information from a web server (I'm using Django) and then I'd send data back to the server.
The thing is I can only find ways to get information from the html page of the url I requested.
How could I use a Python script to get data from the web server? (like making a Django db query but outside Django, using only Python) I want to be able to get the information stored in Django without having to go directly to the website (that is, using a Python script).
Thanks in advance,

I guess you'll want to use a REST framework. The most used are django-rest-framework and tastypie

Related

How do you use a web.py application in Wordpress?

I have written an application in python to collect data from a javascript form and returned the processed text. It is based entirely off of the code here (but a lot more complex, so I have to use python for this).
https://kooneiform.wordpress.com/2010/02/28/python-and-ajax-for-beginners-with-webpy-and-jquery/
(note to people who like to edit...please leave this link in place since it shows all the relevant code sections in python and javascript).
I need to use this in wordpress (since that's what runs my site) and I honestly have no idea how to pull this off. Webpy can run with Apache CGI, but the documentation (http://webpy.org/cookbook/cgi-apache) is only clear if one wants to navigate directly to the python app as its own page.
I'm hoping someone here has expertise in how to embed this all within a Wordpress page/post?
Thanks!!
As far as I know, there is no native way to run Python code inside a WordPress site just like php. In fact, if you are not doing anything unique to Python, I would suggest you to use php, which supports regular expression and can be used in WordPress by installing the plugin "Insert PHP".
If you really want to use Python, then you need an API endpoint where you connect the function to your website. You would have to look into Azure Function App/AWS lambda on which you write a function app to work as a backend. Then whenever someone request your website, your website would do an HTTP request to that API.
Can you explain what exactly you want to do on your website?

Display Data In Real Time With Django

I have a simulator application that continuously spits out data, formatted in JSON, to a given host name and port number (UDP). I would like to be able to point the simulator output to a Django web application so that I can monitor/process the data as it comes in.
How do I receive and process data in real time using Django? What tools or packages are available to accomplish this? I did come across this answer: How to serve data from UDP stream over HTTP in Python?, but I don't completely understand.
Ex: Similar to this page: http://money.cnn.com/data/markets/
ALSO, I don't need to store any of the streaming data in a database. I just need to perform lookups based on the streaming data. Maybe it's not a Django issue at all?
Using Javascript.
Create a webpage with all the results, and then use javascript to collect the data from the page, and update it every X seconds.
Have the webpage be the JSON data, and the javascript grab it an interpret it.
get html code using javascript with a url
Then update the page using javascript. ww3 schools has great JS tutorials

Website for machine design calculations

I wish to create a website to compute simple stress calculations for machine design. I have attached a sample below. What tools do I need to build something like what I have shown in the attached image. I want the user to perform the calculation, save for later use and print it in the form of a report. Please note the items in boxes are user input.
Looks like you want to create a web app. If your language of choice is python, you can use the Django web framework. Web frameworks like Django and Ruby on Rails help organize your files for websites. You can create a web app using Django but all your python code will be running on the server. Any calculations would need to be sent as a request to the server and returned to the client. JavaScript runs on the client computer and would be better for your application. You can also store cookie data in the client computer to access later. In addition you should know some html and CSS to display your app. The html, CSS and JavaScript can all be implemented in the Django framework.

How to create a login screen using core python language

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/ .

How do you submit a form to an app engine python application without refreshing the sending page?

As a newbie to app engine and python I can follow the examples given by Google and have created a python application with a template HTML page where I can enter data, submit it to the datastore and by reading back the data, just sent, recreate the sending page so I can continue adding data and store again. However what I would like to do is submit the data, have it stored in the datastore without the sending page being refreshed. It seems like a waste of traffic to have all the data sent back again.
Sounds like you want to look into AJAX. The simplest way to do this is probably to use the ajax functions in one of the popular Javascript libraries, like jQuery.
AJAX. If you want a specific resource concerning AppEngine -
http://code.google.com/appengine/articles/rpc.html (uses Python) is very good.
Here is a good link to understand Communication with Server on Google App Engine
Have a look at Pyjamas pyjs.org
It's a Python Compiler for web browsers. Write your client side in Python and Pyjamas will compile it into JavaScript.

Categories