Google App Engine: Using Ajax - python

I was planning to develop an ecommerce site using Google App Engine in Python. Now, I want to use Ajax for some added dynamic features. However, I read somewhere that I need to know PHP in order to use AJAX on my website. So, is there no way I can use Ajax in Python in Google App Engine? Also, I would be using the webapp2 framework for my application.
Also, if its possible to use Ajax in Google App Engine with Python, can anyone suggest some good tutorials for learning Ajax for the same?

AJAX has nothing to do with PHP: it's a fancy name for a technique whose goal is to provide a way for the browser to communicate asynchronously with an HTTP server. It is independent of whatever is powering that server (be it PHP, Python or anything).
I fear that you might not be able to understand this yet, so I recommend you to Google about it and experiment a lot before starting your project.

AJAX is an asynchronous technique to get the data from server.It is a plain javascript code.
You can use jquery to implement the AJAX calls.
For e.g.
$.ajax({
url:"/test",
type:'GET',
success: function(html){
$('body').append(html);
}
});
This script will make an asynchronous call to the server to the URL(e.g. http://your-app.com/test). Your server should return an html content, which can be appended to the existing page content. Your server can return any type of data i.e. JSON,XML,etc;

Related

Why do I need web api to link between django and other js framworks

why do i need a web API to link between django and other JS frameworks for example django with angular?
And is it necessary to build a web API like (REST API) to link between back end and front end?
Django is not JS library. It's a Python-based server framework. But your JS library communicates with a server via REST Api. So you need a web API to link between django and other JS frameworks.
Without more work than it is worth, the DJango and Angular frameworks probably cannot pass data between one and the other, since both run at the same logical level in the stack.
REST APIs are the generally accepted mechanism for communicating between SPAs implemented in different frameworks.

How to create a Python API and use it with React Native?

I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.

Using aws chalice to build a single page application?

Has anyone here ever worked with chalice? Its an aws tool for creating api's. I want to use it to create a single page application, but Im not sure how to actually serve html from it. I've seen videos where its explored, but I can't figure out how they actually built the thing. Anyone have any advice on where to go, how to start this?
You wouldn't serve HTML from Chalice directly. It is explicitly designed to work in concert with AWS Lambda and API Gateway to serve dynamic, API-centric content. For the static parts of an SPA, you would use a web server (nginx or Apache) or S3 (with or without CloudFront).
Assuming you are interested in a purely "serverless" application model, I suggest looking into using the API Gateway "Proxy" resource type, forwarding to static resources on S3.
Worth noting that it's probably possible to serve HTML from Chalice, but from an architecture perspective, that's not the intent of the framework and you'd be swimming upstream to get all the capabilities and benefits from tools purpose-built for serving static traffic (full HTTP semantics w/ caching, conditional gets, etc)
Add Response from Chalice and the use it to set the response headers and you're g2g.
from chalice import Chalice, Response
return Response(template, status_code=200, headers={"Content-Type": "text/html", "Access-Control-Allow-Origin": "*"})
I read about it here;
https://medium.com/#tim_33529/creating-a-serverless-blog-with-chalice-bdc39b835f75

Creating a python web server to recieve XML HTTP Requests

I am currently working on a project to create simple file uploader site that will update the user of the progress of an upload.
I've been attempting this in pure python (with CGI) on the server side but to get the progress of the file I obviously need send requests to the server continually. I was looking to use AJAX to do this but I was wondering how hard it would be to, instead of changing to some other framerwork (web.py for instance), just write my own web server for receiving the XML HTTP Requests?
My main problem is that sending the request is done from HTML and Javascript so it all seems like magic trickery at the moment.
Can anyone advise me as to the best way to go about receiving these requests on the server?
EDIT: It seems that a framework would be the way to go. Would web.py be a good route to take?
I would recommend to use a microframework like Sinatra for Ruby. There seem to be some equivalents for Python. What python equivalent of Sinatra would you recommend?
Such a framework allows you to simply map a single method to a route.
Writing a very basic HTTP server won't be very hard (see http://docs.python.org/library/simplehttpserver.html for an example), but you will be missing many features that are provided by real servers and web frameworks.
For your project, I suggest you pick one of the many Python web frameworks and run your application behind Apache/mod_wsgi.
There's absolutely no need to write your own web server. Plenty of options exist, including lightweight ones like nginx.
You should use one of those, and either your own custom WSGI code to receive the request, or (better) one of the microframeworks like Flask or Bottle.

Web based wizard with Python

What is a good/simple way to create, say a five page wizard, in Python, where the web server component composes the wizard page content mostly dynamically by fetching the data via calls to a XML-RPC back-end. I have experienced a bit with the XML-RPC Python module, but I don't know which Python module would be providing the web server, how to create the static content for the wizard and I don't know how to extend the web server component to make the XML-RPC calls from the web server to the XML-RPC back-end to be able to create the dynamic content.
If we break down to the components you'll need, we get:
HTTP server to receive the request from the clients browser.
A URL router to look at the URL sent from client browser and call your function/method to handle that URL.
An XML-RPC client library to fetch the data for that URL.
A template processor to render the fetched data into HTML.
A way to send the rendered HTML as a response back to the client browser.
These components are handled by almost all, if not all, Python web frameworks. The XML-RPC client might be missing, but you can just use the standard Python module you already know.
Django and Pylons are well documented and can easily handle this kind of project, but they will also have a lot of stuff you won't need. If you want very easy and absolute minimum take a look at using juno, which was just released recently and is getting some buzz.
These frameworks will handle #1 and provide a way for you to specify #2, so then you need to write your function/method that handles the incoming request (in Django this is called a 'view').
All you would do is fetch your data via XML-RPC, populate a dictionary with that data (in Django this dictionary is referred to as 'context') and then render a template from the context into HTML by calling the template engine for that framework.
Your function will just return the HTML to the framework which will then format it properly as an HTTP response and send it back to the client browser.
Simple!
UPDATE: Here's a description of how to do wizard style multiple-step forms in Django that should help you out.

Categories

Resources