I have a web app written in Django with mongoengine in a Digital Ocean droplet. During the developing step I used a sample of the main database that is located in a remote enviroment. But now I want to connect the Django web app to the main MongoDB database. How can I do this? With an ssh tunnel (I already use it between both environments)? If so, how do I do such connection? I know how to establish an ssh tunnel with pymongo:
from sshtunnel import SSHTunnelForwarder
import pymongo
server = SSHTunnelForwarder(
(remote_ip_address, 22),
ssh_private_key="/home/username/.ssh/id_rsa",
ssh_username="username",
remote_bind_address=('127.0.0.1', 27017),
)
server.start()
client = pymongo.MongoClient('127.0.0.1', server.local_bind_port)
But how do I do the equivalent connection with the Django web app? At the present moment I have the following definitions in the settings.py file.
# MongoDB settings
MONGODB_DATABASES = {'default': {'name':'dbname'} }
DATABASES = {'default': {'ENGINE': 'django.db.backends.dummy'} }
Related
Hello I just want to deploy my django project in python anywhere .... and when I run the command python manage.py migrate
it shows this error message django.db.utils.OperationalError: connection to server at "<Host name>" (<IP address>), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
I think that the problem in python anywhere because when I connect to the server in pgadmin using the same info in the settings.py file I don't get any error messages and you have to know that I am using neon.tech for my postgresql database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<the database>',
'USER':'<User>',
'PASSWORD':'<Password>',
'HOST':'<Host>',
'PORT':5432,
}
}
and I am sure that all information is right because I used it to connect to the server in pgadmin in my local machiene
If you are having trouble connecting to a PostgreSQL database in a deployment environment, there are a few things you can check:
Verify that the database is running: Make sure that the PostgreSQL database is running and accessible from the deployment environment. You can check this by attempting to connect to the database using the 'psql' command-line tool.
Check the connection settings: Ensure that the connection settings in your deployment configuration are correct, including the database host, port, database name, user, and password.
Check firewall settings: If you are connecting to a remote PostgreSQL database, ensure that the necessary firewall ports are open to allow incoming connections to the database server.
Check for network issues: Check for any network issues that may be preventing the deployment environment from connecting to the database. For example, if you are deploying to a virtual private cloud, ensure that the network settings are configured correctly.
Check for authentication issues: Make sure that the user and password specified in the connection settings have the necessary permissions to access the database.
Check logs for errors: Check the logs for any error messages that may indicate the cause of the connection issue.
By investigating the above points, you should be able to narrow down the cause of the connection issue and take the necessary steps to resolve it.
I recently finished my django project and i switched my database from the local SQLite database, provided by django, to an online postgreSQL database provided by elephantSQL. Clearly, by entering my database credential in the setings.py file of my django project i am able to migrate to my new database locally while not on my host's bash console. Meaning that, when i run my server on port 8000 it loads my data from the postgreSQL, but when i push my website to PythonAnywhere and try to run my migrations from the bash console of PythonAnywhere it throws out the following error:`
django.db.utils.OperationalError: connection to server at "'USER'.db.elephantsql.com" ("DATABASE_IP"), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
`
I even changed my database Host from elephanSQL to nhost, but still it promps the same result.
I have a nextjs app and Django app running on a Linux server. For the purposes of SSR, I am trying to get data from the Django app to the nextjs app using getServerSideProps. The easiest I would do this is to send a request from the nextjs app to the Django app.
This was relatively easy for me to do in development. Requests would be sent to http://localhost:8000, since the Django app was using port 8000, from port 3000 which is the port the nextjs app is using.
However, in our production server, the Django app run on a Unix socket, served via gunicorn.
upstream app_server {
server unix:/path/to/gunicorn.sock fail_timeout=0;
}
How can I request for data from the Django app to the nextjs app when the Django app is accessible via Unix socket?
i have a MySQL database in cpanel and i want to connect my django project to this database when i try to connect it it show a message that i can't connect to localhost but i don't want to connect to localhost i want to connect to my remote database in cpanel.
i have tried to connect to (MySQL workbench) and it connected without a problem.
This is a picture of my settings and error
I Have no idea how to set things up on this fresh centOS 7 server, how to host my django app with postgre db in this server?