How to make an api completely independent from the main Django Project? - django

I have a django project that is hosted internally, and this project feeds the database. I need an API that serves the data of that database to a public domain (that api does not do any DML only selects), but this API needs be hosted in a diferent machine and even if the project that is hosted internally explodes that api needs to keep working.
I am using DRF for the api
I did an api project that has its own apps, views, serializers and models(those models connect to the db existing table like this) and only have the fields that I need represented. Is this the right way to do this or am I missing something? The thing that I am worried is if one of the columns of a model changes name i will have to change the model in the api, but that is a very rare modification.

I don't know if I understood the question correctly but it seems from your question that you have a DJANGO project along with the DATABASE hosted on a particular machine. If that is the case then if your server goes down external API's will not be able to fetch your data.
If on the other hand you have a dedicated server or RDBMS for only your database then you will be able to fetch the data using any API connecting to that database server.

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 prevent employees to work from home on the company's django application

I built an ERP for a small company using Django 1.11. They are expanding now and have other companies joining them and now also use the system I built.
The problem now is that some of the companies do not want their employees to be able to work from outside of the company's premises; remotely. Is there a way to achieve this on the Django application? Is there a way to tweak the Django's allowed_host setting for this purpose? Should I be checking for the location of the user connecting to the app? If so, how do I prevent the app from being fooled by those using a VPN service?

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.

Cloudfoundry how to let two apps sharing one database service

I bind a postgresql service for two apps. They both update the database. Problem is that I use one of the app to create the tables(database schema) by using spring jdbc namespace. But since the other one is provisioned to use a different user name and password. It can not access the tables created by another one. Anyway cloudfoundry to provide the flexibility to resolve the issue?
For Spring apps, this can be achieved by taking the advantage of "auto-reconfigure". CF detects the bean of class javax.sql.DataSource under certain conditions and then replace the properties such as username or password with values of provisioned ones. You can find very detailed instructions here: http://docs.cloudfoundry.com/frameworks/java/spring/spring.html
Therefore for your 2 apps you can both configure the datasource connection as the same format. As long as you bind the same postgresql service to these 2 apps, although CF will inject different values to both apps, they can access same table without any explicit configurations.