(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
Related
I am trying to make this blog website for my university, I am using flutter for the frontend and DRF for the backend. I have some questions regarding these.
Do I need to host my DRF API in order to fetch data from the server? will it work if I use the free version of heroku?
Is there a way I can access the Django admin panel from the flutter frontend? like, assign new users using the admin panel that Django offers?
Thank you
Yes it needs to be hosted if you want to fetch data from the server in production. The free version of Heroku is an excellent option for this.
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.
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.
I am working with a legacy web application based off of Turbogears 1.1 (CherryPy 2.3) and I would like to integrate it with a Django 1.4 web application. What I would like to do ideally is find some way for both applications to share authentication/session state so that the experience is seamless to the user.
Both applications can run on the same server and technically can access the same mysql database instance.
Initial thoughts are that this could be achieved by:
Storing session data in a shared database
Use the Django application as a 'master' that would issue requests via http to the turbogears application
Running the Django application from within Cherrpy via the internal CherryPyWSGIServer
Any other suggestions would be welcome!
I would suggest looking into creating a custom Django auth and session backend which reuses the existing Turbogears data. You will likely also find it necessary to use Django 1.5's configurable user model.
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/