We have two django applications running on the same server that interact with an API that uses oauth. They function as expected, communicating with each other, when run under the django development server. However, when deployed using apache/wsgi they don't work together.
(To be more specific, one application is an instance of the Indivo server; the other one is a custom application that interacts with Indivo.)
What is the best way to trouble shoot this?
Make sure that the Django instances are working by themselves first. For example, one app could be started under Apache, and the other using ./manage.py runserver. Reverse which one is running using Apache and verify that all works as expected.
Use the Apache error logs to look for errors such as failed requests.
Since one of your apps appears to implement a web API, use something like the Google Chrome Postman App to exercise the site from a web browser.
Learn how to use the Django logging framework to log information about your apps as they execute.
Related
I want to make a project, which uses Django as backend, PostgreSQL as database and FastAPI with Django REST Framework for REST.
Don't see any problems with making a project just with Django, DRF and Postgres, but face with difficulties when speak about FastAPI and DRF at the same time.
So there is no problem in connecting Postgres to Django, and there is no problem to make endpoints for DRF.
But how can I connect fastapi? Where to place endpoints and how to run all this stuff together?
In some examples I saw that FastAPI isntance is initiated in WSGI.py and then server runs from calling commands such like this:
uvicorn goatfish.wsgi:app
But i am not sure that it works like this when I mix more than only Django and FastAPI.
I want to use FastAPI for optical character recongnition and DRF for user registration, logins etc.
Are there any advices about making project with such a structure? Or maybe someone have a repository with such kind of project on github?
EDIT: Hope to see answers here, but for now I only see the solution in making classic Django + DRF app, then make FastAPI app with endpoints, run these apps on different ports and do some chain of actions:
From django app we load an image to form and when we submit this form we send POST request to FastAPI endpoint, which will run OCR process and then return JSON with recognized text and then will send this JSON to the Django Callback endpoint, which will process it and save to the database.
What do you think about such thing?
I think, you may:
Mix of fastapi+django. But this is only for replace DRF and use fastapi as rest framework.
Microservices. You may to run Django on one port, fastapi - another. And both may to use one shared database.
Mircoservices. All from point 2, but some api tasks (for example sign-in/sign-up) on Django and another - on fastapi.
As an alterantive you could use django ninja.
It uses similar concepts as FastAPI (Routes, Pydandantic Model Validation, Async Support) but is an Django app.
Which of course is more the monolithic approach but still valid.
Well, so after few days of thinking about I decided, that there is no sense in a question which I asked :)
Here we should talk about microservice architecture, where such kind of problem just doesn't exist. All we need is to make as much services as we need in our project using any framework (Django, FastAPI, Flask, Ruby etc.) and make connections between them.
As example I can run my main Django server on port 8000, my FastAPI server on port 5000 and my DRF service on port 6000. And then I can just do whatever I want from my main Django server making requests to endpoints of FastAPI and DRF.
So that's very simple example, now I'm diving deeper into microservice architecturing, but that's definitely what I need.
Is it reliable to build desktop applications using web frameworks like Django?
The idea is to
build the interface with HTML, CSS, and JavaScript
use Python and Django for backend operations (calculations, storage and databases, etc)
and then run a server locally so that
the interaction with the application is done through the browser
other local devices can access the application by connecting to the device on which the server is running.
If that is possible and yields a reliable experience, then
is the development server that comes with Django enough? If no, what servers are most suitable for our purpose? Is Nginx good for example?
what database should be used? PostgreSQL, MySQL, etc? The app will need to store a large number of entries.
I've never done this, but I can't see why not. You can use the Django REST Framework to create an API that your desktop application can talk to, in exactly the same way as you might with a JavaScript single page app.
But no, you should not use the dev server for production, even in a limited scenario like this. Apache/mod_wsgi or nginx/gunicorn are simple to set up and deploy.
For the database, it makes no difference. The Django core devs prefer postgres, but you should use whatever you are comfortable with.
You are asking for a webApp, so yes you can. Is not use the Django server, instead is very common use nginx for Django, and the best database is postgres for Django.
If you want to pass your project like a desktop app is better use Django server and SQLite for avoid create a new database server.
Database
I find this answer explaining why is postgres better for Django
I am very comfortable with Django, and I was wondering about whether there is some way to convert a Django web app into a Desktop app (may be not 100%), so that I can distribute it to users, instead of learning a GUI framework.
Thanks
Maybe not exactly what you are looking for, but if you really, really don't want to learn a GUI framework, in your place I'd consider packaging your Django web application with a small web server in the distributable package, with the Django app configured to run on localhost on the web server. Then I'd include a script that launches a browser pointing at the starting page of your Django app as the "executable".
If not configured properly this could be considered weak from a security point of view.
I'm building a small web service. To showcase what the service can do I am going to build a lite-weight interface. I'm having a hard time figuring out how my REST API and regular Django views can play nicely together.
Here's my setup:
Using django-piston to build a simple CRUD REST web service.
Using Django views with httplib2 to GET/POST to/from that web service.
Both are being run from the same Django project (and thus same web server).
Right now I have simple read REST service working in the browser. But when I try to use httplib2 from the Django view the request just hangs.
My questions:
-Am I thinking about this the right way?
-Is there a better way to accomplish this?
-Should my REST web service be a different project (and web server) than my REST interface?
Any help would be greatly appreciated!
Generally, I'd demonstrate an API working via unit tests, rather than live views, but can see how that might not be what you need.
So (in line with akonsu's comment above) if you're experiencing this problem local dev, it's the single threaded devserver that's blocking the API from running while the view is executing.
Have you tried a multi-threaded version of the runserver? Like this one?
I am given a responsibility in my project to develop a Equipment tracking tool with following requirements
New Equipment can be added by admin to a particular user
Once equipment is assigned to a person he will a request to accept the request so he will be responsible
User can transfer his equipment to other users.
At the same time Admin should be sent a mail or message whenever there is a change in status.
It should be deployed locally on a PC( So it is not actually a web app) that is connected to network which can be accessed by everyone
I thought I can use Django for this( I am new to it ), but I do not know much about deployment on a local PC , How can I do this, or is there any better Idea for this?
It still sounds like you want a web app, you just won't be deploying it on a traditional web server. One thing to note, client versions of Windows (XP, Vista) will limit you to 10 incoming connections per computer.
You'll want to follow these instructions on how to install Django. If you haven't installed python yet, I'll recommend that you install version 2.5, since that will include sqlite, an embedded database that makes it very easy to get started developing with Django. Django includes its own development web server, which you will come across naturally as you go through the tutorial.
Start by installing and then jump right into the tutorial. Your deployment options will be much easier to understand once you're comfortable with developing in Django.
Try http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index
and if you should deploy using IIS then try http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer