Django App on AWS Elastic Beanstalk - Unable to Login to admin - django

I've deploy a django app on EBS http://djangosample.elasticbeanstalk.com/
The 'It worked' message shows up fine in the browser. However I just can't login to /admin, it just loads and does nothing. The localserver http://127.0.0.1:8000 works with the same credentials
Only changes I've made in settings is changing the default database to postgres.
Any ideas?
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.postgresql_psycopg2',
> 'NAME': 'postgres',
> 'USER': 'username',
> 'PASSWORD': 'password',
> 'HOST': 'sampledjangoapppostgresql.cmipujlbivbk.ap-southeast-2.rds.amazonaws.com',
> 'PORT': '5432',
> } }

I know you mentioned that you only changed db, but for me this was the problem.
I applied migrations and created a superuser on my ebs. Whenever I tried to login nothing happend, but when I used wrong credentials I got an error. So I assumed my db was setup correctly and had a record for my admin user. I used a seperate production settings file in which I had SESSION_COOKIE_SECURE = True (because django docs recommend this in production)." However I guess this failed the login, because I am not using https yet, but I am not entirely sure. After setting this value to false I could login to my admin panel. Hope this works for someone.

Related

Django - Postgres connection

I am super beginner, but want to learn super fast building web application.
I am right now developing an Income-Expense web app on Django Framework (Python, js and Ajax).
I am now stuck with the server and get different errors. Anyone can support me ?
ERROR
"django.db.utils.OperationalError: connection to server on socket "/tmp/.s.PGSQL.5432" failed: fe_sendauth: no password supplied"
I think I shut down everything not properly and when a came back my virtual environment was not working.
Thank You
Don't know what to try more
To resolve the issue, make sure that you have the correct credentials to access your PostgreSQL database. You may need to update the database settings in your Django settings.py file to include the correct database name, username, password, host, and port information.
for example
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '5432',
}
}

Django is trying to authenticate Wrong user for AWS RDS and failing

I am hosting a postgresql database on AWS using the RDS service. I am trying to connect the django project to the aws database using the settings.py file in the django project. I keep getting the following error:
connection to server at "database-1.xxxxxx.us-east-1.rds.amazonaws.com" (xx.xxx.xx.xxx), port 5432 failed: FATAL: password authentication failed for user "local_user"
This error is unexpected because it should not be trying to authenticate the local_user as this is the user for my local postgres server, it should be trying to authenticate the user for the hosted database, which is completely different.
This is what my settings file looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DATABASE_NAME'),
'USER': os.environ.get('DATABASE_USER'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'HOST': "database-1.xxxxxx.us-east-1.rds.amazonaws.com",
'PORT': 5432
}
}
I can't figure out what the issue seems to be. Any help will be appreciated!
I named the environment variable wrong so USER was none!

Connect django web app to postgresql in gcloud

i have been struggling to connect my django web app to a PostgreSQL instance which I set up inside my gcloud account for testing purposes.
I have done the following DB configs in settings.py in Django:
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'instance connection name from gcloud',
'USER' : 'postgres',
'PASSWORD': 'passsss',
'HOST': 'ip-address',
'PORT': '5432',
}
}
the error that I receive in Django after trying to migrate is :
django.db.utils.OperationalError: FATAL: database "..instance connection name from gcloud.." does not exist
I have tried creating a new database "django" and adding it to the NAME with:. This did not work as well. I have also configured in gcloud connections my own computer IP as an authorized network
Normally if I use service like elephantsql it works fine.
Any help would be appreciated. Thanks!
From what I understood from your post, is that you wish to connect from your local pc to a Cloud SQL PostgreSQL instance.
I see that you seem to be following the official documentation already, as you mentioned that you added your IP to authorized networks in order to be able to connect externally.
The cause of your error seems to be due to the format of the NAME parameter.
Are you passing it in this format?
PROJECT:ZONE:INSTANCENAME
Here you have all the available options on how to connect externally to a Cloud PostgreSQL instance.
And here you have the documentation of the requirements to connect an external application to a Cloud SQL PostgreSQL instance.
ok finally after a lot of research and wasting couple of hours I managed to find Django configs in digital ocean docu... pretty weird
This works:
'''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'my_django_db',
'USER' : 'user1',
'PASSWORD': 'pass',
'HOST': 'ipv4',
'PORT': '',
}
}
'''

Pythonanywhere:Access denied for user 'Ujwal97'#'10.0.04' (using password:YES) Django

I'm trying to deploy my django app on pythonanywhere by cloning from my github.
When migrating, I'm getting access denied error followed by (using password:YES),here is the a screenshot of that,
Thanks in advance !!
It seems to me like your database settings are wrong. Your database hostname on PythonAnywhere should look something like yourusername.mysql.pythonanywhere-services.com
Check the Database page in your PythonAnywhere dashboard for the correct settings.
Edit: you must use the hostname, username and password from your dashboard in the Django settings file. The adress 10.0.0.4 indicates that your current settings file does not contain the correct settings.
You should configure your DB settings on yourapp/settings.py as mentioned in pythonanywhere guide
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<your_username>$<your_database_name>',
'USER': '<your_username>',
'PASSWORD': '<your_mysql_password>',
'HOST': '<your_mysql_hostname>',
}
}
There is also an existing post on SO that might be helpful

password authentication failed in postgresql with django

I'm trying to learn web development with Django and I was following this guide to do so.
Everything works fine until I run the following:
python manage.py makemigrations
I get this error message:
password authentication failed for user "myprojectuser"
I have checked and rechecked many times and the password is correct in the settings.py file.
Below is the content of the file (settings.py):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
I am using postgreSQL 9.5, python 2.7, and Django 1.10.
From your guide:
"
By default, Postgres uses an authentication scheme called "peer authentication" for local connections. Basically, this means that if the user's operating system username matches a valid Postgres username, that user can login with no further authentication.
"
so I am guessing that if you will create a user for your DB with the same name as your OS local username it might work :)
In case the "DATABASES" setting you showed are not the one you actually use - check if the "NAME" and the "USER" are in lowercase