How to access data in Docker from my Django app? - django

I am new to Docker so I wonder if I have 2 containers, a streamer that pushes data to the queue and vernemq which is the message queue.
How can I access the data to work with it in my django rest api app?
I was wondering is there a way to export or the data and create a separate database in django with it or it's not how it works?
Or is there a way to directly access the data in docker from django app.
Note the django rest api app is not in a docker Image.

depends on how your current Django REST API is configured... if is looking at a Database? is it looking at a series of other your companies RESI APIs, etc?
I can edit this with more info once I get a little more details. Don't have enough reputation to write a comment.
BUT I would say the best way if the Django app is looking at a database is to write a script to transfer code from the messaging queue and save to the database.
What I would say though is instead of using a message queue to just have the streamer push it directly to where you have your Django app looking.

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

Firebase-powered app with web service code

I am planning to use Firebase database and want to know how it fits in to the following scenario.
lets say I have a browser app, android app / iOS which uses Web Services to get / insert data, web services talks to the Data Base and returns data to the client.
This way I have to write code once in my web services and all the clients use that to retrieve and insert data to the database.
If I want to use Firebase, will I be following the same approach of having webservices between the client's and the Firebase DB.
I have done some sample Firebase examples where it it gets data from database directly without web services and in this approach we have to write our logic on each client (Web browser/ android app/ iOs app).
I have looked into this article
https://firebase.googleblog.com/2013/03/where-does-firebase-fit-in-your-app.html?showComment=1480073224245#c464815735109872173
The Pattern 2 has the server concept but that does not look appropriate in my scenario.
Can I have my web service and Firebase database and get data Synchronization capabilities.
Correct me if I am wrong and please suggest the approach I need to take.
Thank you for your valuable suggestions in advance.
Thanks & regards,
Rao Burugula
The article you link gives you the most common options for integrating Firebase into your app. Pattern 2 is the easiest way to use the Firebase Database and run your own server-side code:
In this model the Firebase Database sits between the app on the user's device and your back-end code. By using this model, you can still get all the benefits of the realtime synchronization, security rules and scalability, but also have back-end code that runs in a trusted environment.
Of course you can also go for a more traditional three-tier model, where your app server sites between the devices and the database. But in that case the Firebase database won't have direct interaction with your app anymore, so you'll have to take care of the realtime aspects of the synchronization (if you want those) in your own code.
I also recommend reading the Google Cloud documentation on using the Firebase Database and App Engine's Flexible Environments. The architecture described there is the same, but a bit more up-to-date:

Django Post to External Server

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.

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.