Django Post to External Server - django

I am relatively new to Django/Python. I am currently developing a Django system to track entries to a modelling system our company developed.
Clients should be able to post model run data to a database on our server. The data will be coming from a python script. I was able to make it work on my system using somemodelname.objects.get_or_create, but this will not work externally. I understand I should use a package such as requests and found: How to post a django request to external server. However, this assumes the django code (views, etc) is accessible from the client computer.
How can I make this work so the client data is posted from a python script to the Django database?

Sounds like a good use of a RESTful API. Django Rest Framework and Tastypie are both good packages to use with Django.
Basically, with an API, you can expose your database through urls. You'll have a url like: mysitename.com/api/mymodel that can handle different HTTP methods. If you called that with a POST verb, your view would create a new record for your mymodel model. Thus, when your client computer generates the data in a python script, you would use [requests](http://docs.python-requests.org/en/latest/) to send the data in a POST request to the url endpoint, which would create the record in the database.

Related

Displaying data retrieved through GraphQL in a Django website

(Disclaimer : I'm just getting started with Django, and with web dev in general)
I have a backend app that stores different kinds of resources. Some are public and some are private. The application is accessible only to identified users. A GraphQL API allows me to access the resources.
On another server, I'd like to create a website that will be accessible to everyone. I want to use Django to create it.
The website will display a list of resources tagged as "public" in the backend app, with a pagination system and, say, 20 resources by page. The CSS will differ from the backend app and there will be a search section.
From what I understand, I should be able to retrieve the data through the GraphQL API, but I'm a bit confused here. All the documentation and tutos I can find about Django and GraphQL seem to be about setting up a GraphQL API server with Django. All I want to do is to build custom queries and to display them on my different html pages.
How can I do that? Where should I start?
You should connect your project with a GraphQL client. As per my research, I have found that there are implementations and examples for graphene-mongoengine in Flask (Flask has a direct GraphQL client).
Mongoengine Flask with GraphQL Tutorial
For Django you can check this out
Edit- I was able to get the data from my database with python-graphql-client. Now I am able to display them in my template.
Let me know if this helps

How to connect to Django from Spring

I'm trying to find a way of sending data to my web server on Spring framework from Django which controls actions of tensorflow.
If Spring server send a request, is it possible to send a output from Django?
If you have experiences like this, please give me some tips.
You can simply make an HTTP request to your Django server, respond with JSON, and then parse that JSON into a Java class using a library like jackson.
Alternatively you can use a shared database where Spring simply uses JDBC to access the data you are trying to reach.

Where should stripe be integrated in single page application with django backend

I am new to stripe integration. I've looked at couple of examples but I'm unsure where I should integrate stripe in my application. My front-end is in Angular and the backend is in django. Should I integrate stripe in Angular code base or django code base?
Both. Front-end: either use Checkout (Embedded Form) or their Custom Form. This will spit out a token that you must process on the server side. If you are using routing or have a complex app, then you probably want a library to abstract away from Stripe's default behaviors, as it uses a simple form action. This will cause a reload or redirection from the page which could be a problem if you don't want to leave the app. I prefer this lightweight wrapper, though others exist: https://github.com/tobyn/angular-stripe-checkout
Server: You include their library for your language (Python if you want) in a script written to process the token. This is what actually sends the charge to Stripe. Just doing the front-end side only sends them a token which shows up in the logs but does nothing. This is where you create a new customer, charge, subscription, etc. according to the API for your language.
Once you've got that set up, then you'll probably want to listen for their webhooks, save the user that is created in your backend with its created from the initial payment, etc.
You can integrate it both in the front-end and back-end, but if it's a single page app and the backend is REST-ful it makes sense to do it in Angular
See this article for example: https://www.airpair.com/javascript/integrating-stripe-into-angular-app

Can I make a login system for use with embedded systems to login and upload data with Django?

I want to try make a web service where the users can post data into a database, and it also should support data posts by some system that is not used my some user. In the end it should have some type of webAPI to allow other users to make other kind of web services using whatever data it contains in the database.
But my main question is does Django have some type of shell interaction function that I can use to let embedded system to login, then to talk to my web service and post data?
You can build a REST API using one of the packages listed here:
http://www.djangopackages.com/grids/g/api/

Is sending HTTP POSTs to Django Web API via node.js efficient?

I've built a JSON API in Django. I'd like to send real-time updates from an external service to Django to upsert a model.
I am really looking for insight on the best way to design the system with current/upcoming/active frameworks and tools. My thoughts are using node.js/Django/Foreman described below:
Existing Django JSON API
A node.js app, running via Foreman, that's subscribed to some external channel.
That channel sends node a JSON message
Node consumes message and makes an HTTP POST of JSON to a URL within my Django API.
Django API uses the JSON message to upsert a model within the Django application.
Now, it seems that I should be able to eliminate node.js from this equation, and have a service that lives "a little closer to home", home being the Django app, rather than having to cross HTTP.
Question being: Is the solution I have now an efficient approach, and is there a better way of doing things?
How do you need to subscribe to the other service? If the other service calls one of your Urls directly, just make Django listen there.
If the other service requires your side to act as server (non webserver, eg connects to you on some non web port) you will need to let a server run there, but again I wouldn't use Node but rather write a simple Python server (probably using the asynccore module), which you could start via foreman+manage.py and which would have access to models directly, eg wouldn't need to marshal the data into json just to send it to Django.
If you connect to the other service via a simple tcp connection I still would take the non node approach like described above.
P.S.: Don't bother to much about efficiency -- keep your system as simple as possible before developing over engineered solutions.